CloudFormation for AWS DevOps Engineer: Sydney Web Service

Using CloudFormation for Web Service in Sydney Region

Prev Question Next Question

Question

A developer is quite new to CloudFormation and he is trying to use CloudFormation for his new assignment which is a web service in the Sydney region only.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

Correct Answer - B.

Mapping and “FN::FindInMap” are good to use for AMI IDs however in this case, only 1 AMI ID is needed in a unique region so that mapping and FN::FindInMap are not necessary.

Besides, “Mapping” does not belong to “Resources” section so that option 1 is eliminated.

Another mistake for Option D is that the correct function should be “FN::FindInMap”.

The proper method is to use Parameter.

Especially when the parameter is a AWS specific parameter type such as AMI ID, the AWS specific parameter type should be used.

Details please refer to https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-specific-parameter-types.

In this case, the parameter should use AWS::EC2::Image::Id as the parameter type.

Option A & D are incorrect and explained as above.

Option C is partially correct because the AWS specific parameter type should be used.

In this case, it should be AWS::EC2::Image::Id.

Option B is better than.

C.

The developer is new to CloudFormation and wants to use it for creating a web service in the Sydney region. The web service requires an Amazon Machine Image (AMI) ID. There are several ways to specify the AMI ID in CloudFormation. The following are the options with a detailed explanation:

A. Use a mapping section: In this method, the template needs to have a "mapping" section inside the "Resources" section. The "mapping" helps the template understand which AMI ID to use during stack creation. The intrinsic function "Fn::FindInMap" is needed in the template to work with the mapping. The mapping section needs to have the region and the corresponding AMI ID for that region. For example, the following code snippet shows a mapping section for the Sydney region:

yaml
Mappings: RegionMap: ap-southeast-2: AMI: ami-12345678

In the above code snippet, "ap-southeast-2" is the region code for Sydney, and "ami-12345678" is the corresponding AMI ID for the region. During stack creation, CloudFormation uses the region specified in the stack and looks up the corresponding AMI ID from the mapping section using the "Fn::FindInMap" function.

B. Use a parameter section: In this method, a parameter is added to the template for the user to input the AMI ID when the stack is created. The parameter should have the type "AWS::EC2::Image::Id". The following code snippet shows how to add a parameter section for the AMI ID:

c
Parameters: AMIId: Type: AWS::EC2::Image::Id

During stack creation, the user needs to provide the AMI ID as a parameter. The advantage of this method is that the user can specify any valid AMI ID.

C. Use a parameter section with string type: In this method, a parameter is added to the template with a string type. The following code snippet shows how to add a parameter section for the AMI ID with a string type:

yaml
Parameters: AMIId: Type: String

During stack creation, the user needs to provide the AMI ID as a parameter. The disadvantage of this method is that the user needs to know the correct format and syntax of the AMI ID.

D. Use a parameter section with proper limitations: In this method, a parameter is added to the template with a string type and proper limitations such as maximum length, minimum length, etc. The following code snippet shows how to add a parameter section for the AMI ID with proper limitations:

yaml
Parameters: AMIId: Type: String AllowedPattern: "ami-[a-f0-9]{8}" MaxLength: 17 MinLength: 12

During stack creation, the user needs to provide the AMI ID as a parameter, and the input should match the allowed pattern and the length limitations.

E. Use a mapping section with all possible AMI IDs: In this method, a mapping section is added to the template with all possible AMI IDs in all regions. The advantage of this method is that CloudFormation does not need to remember any AMI IDs manually. The following code snippet shows how to add a mapping section with all possible AMI IDs:

yaml
Mappings: RegionMap: us-east-1: AMI: ami-12345678 us-west-2: AMI: ami-87654321 ap-southeast-1: AMI: ami-56789012 ap-southeast-2: AMI: ami-