Question #796
A company runs an application on Amazon EC2 instances in an Auto Scaling group and uses AWS CodeDeploy for deployments. Due to frequent scaling events, instances are constantly replaced. The company wants to automate deployments with the LEAST operational overhead while ensuring new instances are ready for CodeDeploy.
What should a solutions architect recommend?
Configure an Amazon EventBridge rule to trigger an AWS Lambda function when a new instance launches. The Lambda function installs the CodeDeploy agent and registers the instance with the deployment group.
Use AWS CodeBuild to generate a new AMI with the latest application code, update the Auto Scaling group's launch template, and perform an instance refresh to replace existing instances.
Suspend Auto Scaling processes before deployment. After deploying the new code, create a new AMI, update the launch template, and resume Auto Scaling.
Create an AMI with the CodeDeploy agent pre-installed, update the Auto Scaling group's launch template to use this AMI, and link the deployment group to the Auto Scaling group.
Explanation
Answer D is correct because creating an AMI with the CodeDeploy agent pre-installed ensures that every new EC2 instance launched by the Auto Scaling group is immediately ready to participate in CodeDeploy deployments. By updating the launch template to use this AMI and linking the deployment group to the Auto Scaling group, the solution minimizes operational overhead, as no additional steps (e.g., Lambda-triggered installations or manual AMI updates) are required during scaling events.
Other options are less efficient:
- A adds complexity with EventBridge/Lambda and delays agent installation.
- B requires rebuilding AMIs for every deployment, increasing overhead.
- C disrupts scaling processes and requires manual intervention.
Key takeaway: Pre-baking the CodeDeploy agent into the AMI ensures readiness and aligns with Auto Scaling best practices.
Answer
The correct answer is: D