An enterprise manages a web application infrastructure deployed via AWS CloudFormation. The stack includes an Auto Scaling Group (ASG) of Amazon EC2 instances behind an Application Load Balancer (ALB). The instances use AWS Systems Manager State Manager to run an association that installs security agents and configures application dependencies, which takes approximately 8 minutes.
During a recent traffic spike, the enterprise faced two major issues:
1. The ASG rapidly launched multiple new instances. However, because the instance bootstrapping took longer than the default cooldown period, the ASG continuously launched unnecessary instances before the initial ones could start serving traffic, exhausting the regional vCPU quota. Additionally, new instances were registered with the ALB and began receiving traffic before the State Manager association completed, causing client request failures.
2. A subsequent CloudFormation stack update failed and rolled back because operators had manually adjusted security group rules and EC2 instance types directly in the console to mitigate the traffic spike.
Which design strategy should a solutions architect implement to automate deployment, secure configuration compliance, and resolve the drift issues?
- AImplement an AWS CodePipeline that uses AWS CodeDeploy to perform a rolling update of the application configurations on the EC2 instances. Set the CodeDeploy deployment configuration to use a linear traffic-shifting strategy. To resolve configuration drift, configure AWS Config to trigger a custom AWS Lambda function that automatically terminates any drifted EC2 instance and deletes modified security groups to force CloudFormation to recreate them during the next stack run.
- BConfigure the Application Load Balancer health check grace period to 10 minutes to allow the State Manager association to complete. Decrease the Auto Scaling scaling policy's cooldown period to 3 minutes to ensure the group can respond quickly to traffic spikes. To resolve configuration drift, enable automatic drift remediation in the AWS CloudFormation stack settings so that the service automatically reverts any manual console modifications during subsequent stack updates.
- Configure an Auto Scaling lifecycle hook for the transition to pause the instance in a wait state during launch. Update the Systems Manager State Manager association to execute the configuration script and run a command that invokes the complete-lifecycle-action API once configuration is successful. Increase the Auto Scaling group scaling policy's cooldown period to be greater than the 8-minute bootstrapping time. To manage drift, perform CloudFormation drift detection, and manually or programmatically revert the drifted resource attributes to match the template before running stack updates.Answer
- DConfigure an Auto Scaling lifecycle hook for the transition and invoke it via an EC2 User Data script that calls the complete-lifecycle-action API immediately upon instance startup. Set the Auto Scaling group's cooldown period to zero to prevent delayed scaling. To prevent configuration drift, attach a Service Control Policy (SCP) to the organization unit that denies the ec2:ModifyInstanceAttribute and ec2:AuthorizeSecurityGroupIngress actions for all principals, assuming this policy grants exclusive update permissions to the CloudFormation service role.