AWS Certified Developer – Associate / Question #953 of 557

Question #953

A developer is tasked with setting up a scalable web application on Amazon EC2 instances using an infrastructure-as-code approach. The solution must ensure that each deployment creates identical environments and allows for automatic rollback to previous configurations if a deployment fails. The deployment process should handle installation of dependencies and application updates consistently across all instances.

Which solution meets these requirements?

A

Use AWS Elastic Beanstalk to manage the environment. Configure the application versions and environment settings. Use rolling deployments to update instances and enable rollback via version switching.

B

Use AWS CodeDeploy with an AppSpec file to manage deployments. Store the application revisions in an S3 bucket. Configure the deployment group to target the EC2 instances and enable automatic rollback on deployment failures.

C

Use AWS CloudFormation to define the infrastructure in a YAML template. Integrate cfn-init scripts within the template to install software and configure instances during stack creation. Utilize CloudFormation's rollback capabilities to revert changes on deployment errors.

D

Use AWS OpsWorks with Chef recipes to automate configuration. Define the stack layers and recipes to handle installation and updates. Use OpsWorks lifecycle events to manage deployments and rollbacks.

Explanation

The correct answer is C because:

- Infrastructure-as-Code (IaC): CloudFormation uses YAML/JSON templates to define infrastructure, ensuring identical environments with each deployment.
- Automatic Rollback: CloudFormation automatically reverts changes if stack creation/update fails, meeting the rollback requirement.
- Consistent Configuration: cfn-init scripts install dependencies and configure instances during stack operations, ensuring uniformity.

Why other options are incorrect:
- A: Elastic Beanstalk abstracts infrastructure details and focuses on application deployment, not full IaC control.
- B: CodeDeploy manages application deployments but does not handle infrastructure provisioning via IaC.
- D: OpsWorks uses Chef for configuration management but lacks CloudFormation's native IaC and automatic rollback capabilities.

Key Points:
- Use CloudFormation for IaC-driven infrastructure.
- Leverage cfn-init for instance configuration.
- Rely on CloudFormation's rollback for deployment failures.

Answer

The correct answer is: C