DOP-C02 Question 84
Single answerYour organization uses AWS CloudFormation to manage infrastructure as code (IaC). A new requirement mandates that application configurations must dynamically adjust based on the deployment environment (e.g., dev, staging, production). You need to ensure that your CloudFormation templates can handle this requirement with minimal duplication of code and without hardcoding values. Which approach should you take?
- A
Use CloudFormation Parameters to define environment-specific values and reference them in the template.
- B
Create separate CloudFormation templates for each environment with hardcoded values specific to dev, staging, and production.
- C
Use AWS Lambda-backed custom resources to dynamically generate configurations based on the environment.
- D
Leverage CloudFormation Conditions to include or exclude specific resources based on the environment.
Show answer and explanation
Correct answer: A
Explanation
CloudFormation Parameters are specifically designed to handle dynamic configuration needs across different environments. By defining parameters for environment-specific values and passing the appropriate values at stack creation, you can reuse a single template for multiple environments without duplication or hardcoding. This makes Parameters the most efficient and scalable approach for this scenario.
- A. Correct.
This is the correct answer. CloudFormation Parameters allow you to define environment-specific values that can be provided at runtime. This approach avoids hardcoding and supports reusability.
- B. Incorrect.
This is incorrect. Creating separate templates for each environment leads to code duplication and is not scalable. It violates the principles of DRY (Don't Repeat Yourself).
- C. Incorrect.
This is incorrect. While Lambda-backed custom resources could be used, this approach introduces unnecessary complexity for a requirement that can be fulfilled using built-in CloudFormation features like Parameters.
- D. Incorrect.
This is incorrect. CloudFormation Conditions are useful for resource inclusion/exclusion but are not designed for dynamically adjusting configurations across environments.