Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find EC2 instances running a certain AMI in order to delete both AMI and EC2 instances? [closed]

I have launched several EC2 instances with my custom AMI. Now I want to completely delete the AMI so firstly I need to terminate all instances running that AMI. Is it possible to do with AWS's API?

For down-voters: Recommended cleanup process from AWS instructed me to terminate all instances running the AMI http://aws.amazon.com/articles/637. The reference can be obsolete but no need to down vote the question.

like image 915
wz366 Avatar asked Dec 08 '25 16:12

wz366


2 Answers

You can delete the AMI without deleting any instances that were created using that AMI. Your question makes it sound like that's not possible.

You can easily browse the EC2 instances in the AWS web console and see what AMI was used to create them. Or you can use the aws ec2 describe-instances command to list all your instances. The output of that command will include the ID of the AMI used to create the instance.

like image 115
Mark B Avatar answered Dec 11 '25 14:12

Mark B


No need to terminate all the instances running that AMI, as per Amazon EC2 documentation you can keep those instances running deregistering the AMI won't effect the functioning of those instances.

When you deregister an AMI, it doesn't affect any instances that you've already launched from the AMI, also it doesn't affect the snapshot that was created for the root volume of the instance during the AMI creation process. You'll continue to incur storage costs for that snapshot.After you deregister an AMI, you can't use it to launch new instances.

Cleaning Up Your Amazon EBS-Backed AMI

To clean up your Amazon EBS-backed AMI

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. In the navigation pane, choose AMIs. Select the AMI, and take note of its ID — this can help you find the correct snapshot in the next step. Choose Actions, and then Deregister. When prompted for confirmation, choose Continue. The AMI status is now unavailable. Note It may take a few minutes before the console changes the status from available to unavailable, or removes the AMI from the list altogether. Choose Refresh to refresh the status.
  3. In the navigation pane, choose Snapshots, and select the snapshot (look for the AMI ID in the Description column). Choose Actions, and then choose Delete Snapshot. When prompted for confirmation, choose Yes, Delete.
  4. (Optional) If you are finished with an instance that you launched from the AMI, terminate it. In the navigation pane, choose Instances. Select the instance, choose Actions, then Instance State, and then Terminate. When prompted for confirmation, choose Yes, Terminate.

For you to refer : http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/deregister-ami.html or EC2 documentation page no-107

like image 29
Kaushal Mewar Avatar answered Dec 11 '25 13:12

Kaushal Mewar