When I create or copy an Amazon Machine Image (AMI) in Amazon Elastic Compute Cloud (Amazon EC2), I receive the "Waiter ImageAvailable failed" error message.
Resolution
Troubleshoot the "Max attempts exceeded" error
If the AMI create or copy process takes longer than the default timeout of 10 minutes, then you receive the following error message:
"Waiter ImageAvailable failed: Max attempts exceeded"
To resolve this issue, implement exponential backoff with retry behavior, or use Amazon EventBridge to monitor the AMI creation or copy process.
Implement exponential backoff
Exponential backoff increases the amount of time between retries. To implement exponential backoff, use a script or code that retries the operation with an increasing delay between each attempt.
The following example script uses the AWS SDK for Python (Boto3) to set a custom WaiterConfig value:
import boto3
from botocore.exceptions import WaiterError
client = boto3.client('ec2')
waiter = client.get_waiter('image_available')
try:
waiter.wait(
ImageIds=['ami-abcdefghxyz'],
WaiterConfig={
'Delay': 15,
'MaxAttempts': 50
}
)
except WaiterError as e:
# Handle the WaiterError exception
print(f"Error waiting for image availability: {e}")
# Add additional logic here to handle the error, such as retrying the operation or logging the issue
Note: Replace ami-abcdefghxyz with your AMI ID, 15 with the delay between attempts in seconds, and 50 with the maximum number of retry attempts.
Use EventBridge to monitor AMI processes
If you use EventBridge, then you don't have to actively monitor your AMI processes. Instead, create an EventBridge rule that detects when the CopyImage or CreateImage events complete. Then, configure an action to notify you when the processes are complete. For example, use Amazon Simple Notification Service (Amazon SNS) to send you an email notification. For more information, see Monitor AMI events using EventBridge.
Troubleshoot the "An error occurred waiting for the image to become available" error
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
You might receive the following error message:
"An error occurred waiting for the image to become available: Waiter ImageAvailable failed: Waiter encountered a terminal failure state"
This error occurs for the following reasons:
- You lack the required AWS Identity and Access Management (IAM) permissions.
- There are temporary issues with the underlying AWS infrastructure.
- You copied or created a large or complex AMI.
Note: Large or complex AMIs that have various software packages and customizations might exceed the default 10-minute timeout when you copy or create them. To resolve this issue, see Troubleshoot the "Max attempts exceeded" error.
To troubleshoot these issues, take the following actions.
Check your IAM permissions
The IAM policy that you attached to the role or user that created or copied the AMI must have the following required permissions:
- ec2:DescribeImages
- ec2:CreateImage
- ec2:CopyImage
Update the IAM policy to include the preceding permissions, and then retry the create or copy process.
Check for issues with the AWS infrastructure
To check the current state of the AMI, run the following describe-images AWS CLI command:
aws ec2 describe-images --image-ids AMI_ID
Note: Replace AMI_ID with your AMI ID.
The output shows you the current state of the AMI. If the State is Pending, then the AMI creation or copy process is still in progress. However, if the State is Failed, then there might be underlying infrastructure issues.
High load or hardware issues can cause temporary issues when you create or copy AMIs. In this scenario, wait between 5 and 10 minutes, and then retry the create or copy process. To check for ongoing issues that affect your AWS Region or AWS service, check Service health on the AWS Health Dashboard.
Troubleshoot further issues
If you still encounter issues, then check the AWS CloudTrail Event history to identify issues with the CopyImage or CreateImage events. Check for error messages, failure reasons, exceeded service quotas, and access issues. For more information, see Log Amazon EC2 API calls using CloudTrail.
If there are no ongoing issues and the operation fails even after you waited between 5 and 10 minutes to retry it, then open an AWS Support case.