Question

Difficulty: MediumAuto Scaling and Elasticity

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.

  1. 1The Auto Scaling group selects an instance for termination and transitions its state to Terminating:Wait.
  2. 2An Amazon EventBridge rule detects the transition and triggers an AWS Systems Manager Run Command script to run on the instance.
  3. 3The Systems Manager Run Command script completes the log backup by uploading the log files to the Amazon S3 bucket.
  4. 4The script invokes the CompleteLifecycleAction API call with the CONTINUE result to signal completion.
  5. 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

1
Identify the initial event that pauses the scale-in process.
The Auto Scaling group selects the instance and transitions it to the Terminating:Wait state.
Lifecycle hooks intercept termination to run custom tasks, starting with placing the instance in a wait state.
2
Determine how the backup orchestration is triggered.
Amazon EventBridge detects the Terminating:Wait transition and triggers Systems Manager Run Command.
EventBridge rules are used to capture lifecycle state changes and trigger automation targets.
3
Perform the custom log backup task on the instance.
The Systems Manager Run Command script successfully uploads the application logs to the S3 bucket.
The instance must remain running in the wait state while the files are being transferred.
4
Signal completion to the Auto Scaling group.
The script invokes the CompleteLifecycleAction API call with the CONTINUE result.
An explicit API call is required to tell the ASG that the custom action has finished and it can proceed.
5
Complete the lifecycle transition and terminate the instance.
The Auto Scaling group transitions the instance to Terminating:Proceed and terminates the EC2 instance.
Receiving the CONTINUE result allows the Auto Scaling group to resume and complete the termination workflow.

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
Rate this question