What happens when I delete a shared AMI?

2 minute read
0

I want to know what happens to the Amazon Elastic Compute Cloud (Amazon EC2) instances that I launched from a shared Amazon Machine Image (AMI) that I delete. I also want to know how to correct errors that I receive when launching new instances from the deleted AMI.

Resolution

When you delete or deregister the AMI that you used to launch running instances, the instances aren't affected. You can't launch new instances from a shared AMI that you deleted.

If you try to launch a new instance from a shared AMI that you deleted, then the following errors occur:

  • "Error while launching Instance using CLI/Terraform : An error occurred (InvalidAMIID.NotFound) when calling the RunInstances operation: The image id '[ami-XXXXXXX]' does not exist."
  • "Error: The AMI ID (ami-XXXXXX) is not valid. The AMI may no longer exist or may be specific to another account or region."

To resolve these errors, use of the following methods:

Use the AWS CLI

Run the following AWS Command Line Interface (AWS CLI) command to replace the deleted AMI ID:

aws ec2 run-instances \
—image-id ami-XXXXXXXX \ <-------- ami-XXXXXXXX this ami is deleted/de-registered
—count 1 \
—instance-type m5n.2xlarge \
—security-group-ids <SecuritygroupID> \
—subnet-id <subnetID> \
—tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=demo-server}]' 'ResourceType=volume,Tags=[{Key=Name,Value=demo-server-disk}]'

Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you're using the most recent AWS CLI version.

Modify the launch template

  1. Open the Amazon EC2 console.
  2. Choose Launch template.
  3. Under Instances, select the launch template that you created with the deleted AMI.
  4. Choose Action, Modify Template.
  5. Choose Application and OS Images (Amazon Machine Image), Select new AMI.
  6. Choose Create template version.

Related information

Modify a launch template (manage launch template versions)

How can I recover an accidentally deleted AMI?

AWS OFFICIAL
AWS OFFICIALUpdated 9 months ago