An organization hosting a web application on AWS uses an Amazon EC2 Auto Scaling group (ASG). A SysOps administrator is configuring a scale-in lifecycle hook to back up application logs to an Amazon S3 bucket before any instance is terminated. A target tracking policy has just triggered a scale-in event.
Order the steps to show the sequence of events that occurs when an instance is terminated using this lifecycle hook, from the start of the scale-in process to the final termination.
- 1The Auto Scaling group selects an instance for termination and transitions its state to Terminating:Wait.
- 2An Amazon EventBridge rule detects the transition and triggers an AWS Systems Manager Run Command script to run on the instance.
- 3The Systems Manager Run Command script completes the log backup by uploading the log files to the Amazon S3 bucket.
- 4The script invokes the CompleteLifecycleAction API call with the CONTINUE result to signal completion.
- 5The Auto Scaling group transitions the instance to Terminating:Proceed and terminates the EC2 instance.
Answer
The correct sequence begins when the Auto Scaling group selects the instance and transitions it to the Terminating:Wait state. Next, an EventBridge rule detects this transition and triggers the Systems Manager Run Command script. The script runs on the instance and uploads the logs to Amazon S3. Once complete, the script invokes the CompleteLifecycleAction API with the CONTINUE result, which allows the Auto Scaling group to transition the instance to Terminating:Proceed and terminate the instance.
The correct order follows the logical flow of the Amazon EC2 Auto Scaling scale-in lifecycle hook. First, the ASG identifies the instance to terminate and pauses termination by putting the instance into the 'Terminating:Wait' state. This state transition generates an EventBridge event, which triggers the Systems Manager Run Command. The Run Command script then executes on the instance to back up the logs to Amazon S3. Once the backup is complete, the script calls the CompleteLifecycleAction API with a CONTINUE result. Finally, the ASG transitions the instance to 'Terminating:Proceed' and terminates the instance.
Step-by-Step Solution
Key Concept
Auto Scaling lifecycle hooks suspend instance state changes, allowing custom workflows (such as log archiving via Systems Manager and EventBridge) to execute before the instance proceeds to the next state.
Estimated Time:2m 0s