How can I delete an image (AMI) in AWS EC2 using the SDK?

I use CreateImage()to create a new AMI from an existing instance, and I was hoping there DeleteImage()would be one that would work the other way around. Unfortunately, this method does not exist on EC2Client.

What is the correct way to remove AMI via SDK using C #?

+1
source share
2 answers

There is DeregisterImage()one that should do what you want. Please note that you will be able to delete any pictures that may subsequently have an image.

+2
source

Here is a quick snippet:

AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client();

DeregisterImageRequest deregisterImageRequest = new DeregisterImageRequest();
deregisterImageRequest.ImageId = AMIName;

DeregisterImageResponse deregisterImageResponse = new DeregisterImageResponse();
deregisterImageResponse = ec2.DeregisterImage(deregisterImageRequest);

Remember to handle exceptions and delete snapshots.

.

blockdevice DescribeImageAttributeRequest, - " ":

DescribeImageAttributeRequest describeImageAttributeRequest = new DescribeImageAttributeRequest().WithImageId("ami-name").WithAttribute("blockDeviceMapping");

DescribeImageAttributeResponse describeImageAttributeResponse = new DescribeImageAttributeResponse();

describeImageAttributeResponse = ec2.DescribeImageAttribute(describeImageAttributeRequest);

: https://forums.aws.amazon.com/message.jspa?messageID=231972

+3

Source: https://habr.com/ru/post/1788572/


All Articles