Question #1021
A developer is using AWS CloudFormation to deploy an Amazon RDS instance. The developer needs to set the RDS instance's allocated storage based on the environment parameter of the template. The template contains mappings of EnvironmentConfig for each environment's storage size.
The environment parameter and EnvironmentConfig mappings are as follows:
Environment parameter:yaml<br>Parameters:<br> Environment:<br> Type: String<br> Default: dev<br> AllowedValues:<br> - dev<br> - test<br> - prod<br> Description: The name of the deployment environment.<br>
EnvironmentConfig mappings:yaml<br>Mappings:<br> EnvironmentConfig:<br> dev:<br> Storage: 100<br> test:<br> Storage: 200<br> prod:<br> Storage: 300<br>
Which statement will meet these requirements?
AllocatedStorage: !GetAtt [EnvironmentConfig, !Ref Environment, Storage]
AllocatedStorage: !FindInMap [EnvironmentConfig, !Ref Environment, Storage]
AllocatedStorage: !Select [EnvironmentConfig, !Ref Environment, Storage]
AllocatedStorage: !ForEach [EnvironmentConfig, !Ref Environment, Storage]
Explanation
The correct answer is B: AllocatedStorage: !FindInMap [EnvironmentConfig, !Ref Environment, Storage].
Why B is correct:
- The !FindInMap
intrinsic function retrieves values from a CloudFormation mapping. Its syntax is !FindInMap [MapName, TopLevelKey, SecondLevelKey]
.
- Here, EnvironmentConfig
is the map name, !Ref Environment
resolves to the environment parameter value (e.g., 'dev'), and Storage
is the second-level key.
- This matches the structure of the provided mappings, where each environment (dev/test/prod) has a Storage
value.
Why other options are incorrect:
- A: !GetAtt
retrieves attributes of AWS resources (e.g., EC2 instance ID), not mapping values.
- C: !Select
returns an item from a list by index (e.g., !Select [0, ["a", "b"]]
), which is unrelated to mappings.
- D: !ForEach
is not a valid CloudFormation intrinsic function.
Key Points:
- Use !FindInMap
to access values in CloudFormation mappings.
- Mappings are static configurations defined in the template, not dynamic resources.
- Parameters and mappings are often combined to customize templates for different environments.
Answer
The correct answer is: B