-1

Is there a way to find out AMI's associated with an Instance?

Like for example, I have test_instance. I would like to find out AMI's that have been generated with this instance.

So, basically I am trying to terminate the instance and all the AMI's and volumes associated with it.

Shabbir Bata
  • 861
  • 2
  • 11
  • 23
  • Sorry, have you tried to search in the AWS Console? The AMI info will be visible there. You can also get this via CLI: aws ec2 describe-instances --instance-id i-1234567890abcdef0 --query 'Reservations[*].Instances[*].[ImageId,Tags[*]]' http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html When you launch an instance, no AMIs are generated. You cannot terminate the AMI and volume, you can only terminate the instance. – sudo Aug 30 '17 at 20:36
  • @sudo I would like to detach the volumes and delete volume(s) associate with instance. And same with AMI. – Shabbir Bata Aug 30 '17 at 20:41
  • When you terminate instance, by default root volume is deleted (can be changed by DeleteOnTermination proerty) but any additional EBS volumes that you attach at launch, or any EBS volumes that you attach to an existing instance persist even after the instance terminates. So, if you have only root volume, and DeleteOnTermination set to true, you can just terminate the instance and volume will be deleted. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html I have added it as answer as well (due to character limitation). – sudo Aug 30 '17 at 20:50
  • If you want to find AMIs generated from a given EC2 instance then you should tag the AMIs after creation with whatever allows you to correlate with the original instance (an instance ID would be one possibility, though it's a poor choice as instance IDs are ephemeral). – jarmod Aug 30 '17 at 21:11
  • Why do you wish to delete the AMIs? Is the reason they were originally created no longer valid once the instance has been terminated? – John Rotenstein Aug 30 '17 at 23:48

1 Answers1

0

When you terminate instance, by default root volume is deleted (can be changed by DeleteOnTermination proerty) but any additional EBS volumes that you attach at launch, or any EBS volumes that you attach to an existing instance persist even after the instance terminates. So, if you have only root volume, and DeleteOnTermination set to true, you can just terminate the instance and volume will be deleted. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html For the AMI, if you used a public/AWS provided AMI, you cannot delete that. If you are using your own AMI, you have to deregister the AMI and delete the snapshot used to create the AMI. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/deregister-ami.html http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-deleting-snapshot.html

sudo
  • 2,237
  • 1
  • 9
  • 14