AWS
EC2InvalidAMIIDNotFound - EC2 Invalid AMI ID Not Found
Getting an **EC2InvalidAMIIDNotFound** error means the AMI (Amazon Machine Image) ID you specified doesn't exist or isn't available in the current region—the AMI might have been deregistered, is in a different region, or isn't shared with your account. This client-side error (4xx) happens when AWS validates AMI existence. Most common when AMI IDs are incorrect, but also appears when AMIs are in different regions, AMIs have been deregistered, AMI ID formats are incorrect, or AMIs aren't shared with your account.
#Common Causes
- →Identity: IAM policy allows EC2 launch but AMI doesn't exist. Service Control Policy (SCP) restricts AMI access.
- →Network: VPC endpoint AMI restrictions. Cross-region AMI access.
- →Limits: AMI ID does not exist. AMI in different region. AMI has been deregistered. Incorrect AMI ID format. AMI not shared with your account.
✓Solutions
- 1Step 1: Diagnose - Check AMI exists in current region: aws ec2 describe-images --image-ids ami-XXXXX --region REGION --query 'Images[0].[ImageId,Name,State]' --output table. Verify AMI exists and is available.
- 2Step 2: Diagnose - List available AMIs: aws ec2 describe-images --owners amazon --filters "Name=name,Values=*amazon-linux*" --query 'Images[*].[ImageId,Name,CreationDate]' --output table. Find correct AMI ID.
- 3Step 3: Diagnose - Check AMI across regions: Loop through regions: for region in us-east-1 us-west-2; do aws ec2 describe-images --image-ids ami-XXXXX --region $region; done. Verify if AMI exists in different region.
- 4Step 4: Fix - Use correct AMI ID: Verify AMI ID from list. Check for typos. Use exact AMI ID (case-sensitive). Verify AMI format: ami-xxxxxxxxxxxxxxxxx.
- 5Step 5: Fix - Copy AMI to current region or verify sharing: If AMI is in different region, copy it: aws ec2 copy-image --source-region SOURCE_REGION --source-image-id ami-XXXXX --name "copied-ami". Or verify AMI sharing permissions: aws ec2 describe-image-attribute --image-id ami-XXXXX --attribute launchPermission.
</>Code Examples
Verify AMI Exists in Current Region
1#!/bin/bash
2AMI_ID="ami-12345678"
3REGION="us-east-1"
4
5echo "=== Checking AMI in Region: ${REGION} ==="
6AMI_INFO=$(aws ec2 describe-images \
7 --image-ids ${AMI_ID} \
8 --region ${REGION} \
9 --query 'Images[0].[ImageId,Name,State,Platform]' \
10 --output table 2>&1)
11
12if [ $? -eq 0 ]; then
13 echo "✓ AMI exists in ${REGION}"
14 echo "${AMI_INFO}"
15else
16 echo "✗ AMI not found in ${REGION} (EC2InvalidAMIIDNotFound)"
17 echo "Error: ${AMI_INFO}"
18
19 echo "\n=== Searching for Similar AMIs ==="
20 aws ec2 describe-images \
21 --owners amazon \
22 --filters "Name=name,Values=*amazon-linux*" \
23 --region ${REGION} \
24 --query 'Images[*].[ImageId,Name,CreationDate]' \
25 --output table | head -10
26fiCheck AMI Across Different Regions
1#!/bin/bash
2AMI_ID="ami-12345678"
3REGIONS=("us-east-1" "us-west-2" "eu-west-1" "ap-southeast-1")
4
5echo "=== Checking AMI Across Regions ==="
6for REGION in "${REGIONS[@]}"; do
7 echo "\nChecking region: ${REGION}"
8
9 RESULT=$(aws ec2 describe-images \
10 --image-ids ${AMI_ID} \
11 --region ${REGION} \
12 --query 'Images[0].ImageId' \
13 --output text 2>/dev/null)
14
15 if [ ! -z "${RESULT}" ] && [ "${RESULT}" != "None" ]; then
16 echo "✓ AMI found in ${REGION}: ${RESULT}"
17
18 # Get AMI details
19 aws ec2 describe-images \
20 --image-ids ${AMI_ID} \
21 --region ${REGION} \
22 --query 'Images[0].[ImageId,Name,State]' \
23 --output table
24 break
25 else
26 echo "✗ AMI not found in ${REGION}"
27 fi
28doneList Available AMIs and Copy AMI to Current Region
1#!/bin/bash
2REGION="us-east-1"
3
4echo "=== Available AMIs (Amazon Linux) ==="
5aws ec2 describe-images \
6 --owners amazon \
7 --filters "Name=name,Values=amzn2-ami-hvm-*" "Name=architecture,Values=x86_64" \
8 --region ${REGION} \
9 --query 'Images | sort_by(@, &CreationDate) | [-1].[ImageId,Name,CreationDate]' \
10 --output table
11
12echo "\n=== Your Own AMIs ==="
13aws ec2 describe-images \
14 --owners self \
15 --region ${REGION} \
16 --query 'Images[*].[ImageId,Name,State]' \
17 --output table
18
19echo "\n=== Copy AMI from Different Region ==="
20SOURCE_REGION="us-west-2"
21SOURCE_AMI="ami-12345678"
22NEW_AMI_NAME="copied-ami-$(date +%s)"
23
24echo "Copying AMI from ${SOURCE_REGION}..."
25aws ec2 copy-image \
26 --source-region ${SOURCE_REGION} \
27 --source-image-id ${SOURCE_AMI} \
28 --name ${NEW_AMI_NAME} \
29 --region ${REGION} \
30 --output json
31
32if [ $? -eq 0 ]; then
33 echo "\n✓ AMI copy initiated"
34 echo "Check status: aws ec2 describe-images --image-ids NEW_AMI_ID --region ${REGION}"
35else
36 echo "\n✗ Failed to copy AMI"
37 echo "Check AMI sharing permissions and IAM permissions"
38fi↗Related Errors
Provider Information
This error code is specific to AWS services. For more information, refer to the official AWS documentation.