A SysOps Administrator is troubleshooting an AWS CloudFormation template whereby multiple Amazon EC2 instances are being created.
The template is working in us-east-1, but it is failing in us-west-2 with the error code:AMI [ami-12345678] does not exist.
How should the Administrator ensure that the AWS CloudFormation template is working in every region?
Copy the source region’s Amazon Machine Image (AMI) to the destination region and assign it the same ID.
Edit the AWS CloudFormation template to specify the region code as part of the fully qualified AMI ID.
Edit the AWS CloudFormation template to offer a drop-down list of all AMIs to the user by using the AWS::EC2::AMI::ImageID control.
Modify the AWS CloudFormation template by including the AMI IDs in the ג€Mappingsג€ section. Refer to the proper mapping within the template for the proper AMI ID.
Explanations:
Copying the AMI to the destination region will change its ID, so it will no longer match the original ID specified in the template. The template needs to dynamically handle region-specific AMIs.
Specifying the region code in the AMI ID is not valid, as AMI IDs are region-specific and the ID cannot contain the region code as part of its string.
AWS CloudFormation does not support a drop-down list of AMIs through theAWS::EC2::AMI::ImageIDcontrol. This approach is not feasible in the template.
The correct approach is to use theMappingssection in the CloudFormation template to map AMI IDs to specific regions. This ensures the correct AMI is used based on the region.