Follow these steps to launch an EC2 instance with an AMI ID that matches your region:
- Go to the CloudFormation console, and click Create stack.
- Save the following code to a file on your filesystem:
AWSTemplateFormatVersion: "2010-09-09"
Description: Demonstrate CloudFormation Mappings
Parameters:
OperatingSystem:
Description: The operating system to run for the instance
Type: String
Default: Linux
AllowedValues:
- Linux
- Windows
ConstraintDescription: Must be Linux or Windows
Mappings:
RegionMap:
us-east-1:
Linux: ami-035be7bafff33b6b6
Windows: ami-0df43b4f8a07c7c14
us-west-1:
Linux: ami-0799ad445b5727125
Windows: ami-06b499097655a3ab5
Resources:
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId:
!FindInMap
- RegionMap
- !Ref "AWS::Region"
- !Ref OperatingSystem
InstanceType: t2.micro
- Select Upload a template to Amazon S3, and choose the file that you just created. Click Next, and give the stack a name.
- Click Next, and then Next on the following screen.
- Click Create.
- Go to the EC2 dashboard to confirm the creation of the EC2 instance with the correct AMI.
- Delete the stack.