Learn how to create a CloudFormation template that allows you to choose from a list of approved EC2 instance types. Discover the benefits of using parameters with AllowedValues to control the input options for your template.
Table of Contents
Question
A developer is creating an AWS CloudFormation template to deploy Amazon EC2 instances across multiple AWS accounts. The developer must choose the EC2 instances from a list of approved instance types.
How can the developer incorporate the list of approved instance types in the CloudFormation template?
A. Create a separate CloudFormation template for each EC2 instance type in the list.
B. In the Resources section of the CloudFormation template, create resources for each EC2 instance type in the list.
C. In the CloudFormation template, create a separate parameter for each EC2 instance type in the list.
D. In the CloudFormation template, create a parameter with the list of EC2 instance types as AllowedValues.
Answer
D. In the CloudFormation template, create a parameter with the list of EC2 instance types as AllowedValues.
Explanation
The correct answer is D. In the CloudFormation template, create a parameter with the list of EC2 instance types as AllowedValues.
To create an AWS CloudFormation template to deploy Amazon EC2 instances across multiple AWS accounts, the developer can use parameters to customize the template. Parameters enable you to input custom values to your template each time you create or update a stack. You can use parameters to specify the EC2 instance type for the stack to use when you create or update the stack.
To incorporate the list of approved EC2 instance types in the CloudFormation template, the developer can follow these steps:
- In the Parameters section of the CloudFormation template, create a parameter named InstanceTypeParameter. This parameter lets you specify the EC2 instance type for the stack to use when you create or update the stack.
- Assign a parameter type of String to the parameter. This indicates that the parameter value must be a string.
- Assign a default value of t2.micro to the parameter. This is the value that AWS CloudFormation uses to provision the stack unless another value is provided.
- Assign a list of EC2 instance types as AllowedValues to the parameter. This restricts the parameter value to one of the values in the list. The list should include only the approved EC2 instance types, such as t2.micro, m1.small, and m1.large.
- Assign a description to the parameter. This provides information about the parameter and its usage.
The following example shows how to create a parameter with the list of EC2 instance types as AllowedValues in JSON and YAML syntax:
JSON
"Parameters" : {
"InstanceTypeParameter" : {
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : [ "t2.micro", "m1.small", "m1.large" ],
"Description" : "Enter t2.micro, m1.small, or m1.large. Default is t2.micro."
}
}
YAML
Parameters:
InstanceTypeParameter:
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
- m1.small
- m1.large
Description: Enter t2.micro, m1.small, or m1.large. Default is t2.micro.
This solution will meet the requirements because:
- It will allow the developer to choose the EC2 instance type from a list of approved instance types in the CloudFormation template.
- It will provide a default value and a description for the parameter to simplify its usage.
- It will validate the parameter value and prevent invalid or unauthorized values from being entered.
Option A is incorrect because creating a separate CloudFormation template for each EC2 instance type in the list is not an efficient or scalable solution. The developer would have to maintain multiple templates and update them separately whenever there is a change in the configuration or resources. This would add complexity and overhead to the deployment process.
Option B is incorrect because creating resources for each EC2 instance type in the list in the Resources section of the CloudFormation template is not a valid solution. The Resources section of the CloudFormation template defines what AWS resources you want to create and configure. You cannot create multiple resources of the same type with different properties in the same template. You have to use parameters or mappings to specify different values for different resources.
Option C is incorrect because creating a separate parameter for each EC2 instance type in the list in the CloudFormation template is not a practical solution. The developer would have to enter multiple parameter values when creating or updating a stack, which would be cumbersome and error-prone. The developer would also have to use conditional logic or intrinsic functions to select which parameter value to use for each resource, which would add complexity and overhead to the template.
The latest AWS Certified Developer – Associate DVA-C02 certification actual real practice exam question and answer (Q&A) dumps are available free, which are helpful for you to pass the AWS Certified Developer – Associate DVA-C02 exam and earn AWS Certified Developer – Associate DVA-C02 certification.