How to do it...

Follow these steps to launch an EC2 instance with an AMI ID that matches your region:

  1. Go to the CloudFormation console, and click Create stack.
  2. 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

  1. Select Upload a template to Amazon S3, and choose the file that you just created. Click Next, and give the stack a name. 
  2. Click Next, and then Next on the following screen.
  3. Click Create.
  4. Go to the EC2 dashboard to confirm the creation of the EC2 instance with the correct AMI.
  5. Delete the stack.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset