You use CloudFormation to launch an Auto Scaling group.
In the CloudFormation stack, you create a lifecycle hook in the ASG that puts a new instance in the Wait state while the custom script of the user data is running.
The script installs the web application, initializes customer data and performs a health check of the instance.
After the health check has passed, how would you put the instance back to the InService state in the Auto Scaling group?
Click on the arrows to vote for the correct answer
A. B. C. D.Correct Answer - B.
Option A is incorrect because the record-lifecycle-action-heartbeat command is used to restart the timeout period and keep the instance in the Wait state.
It cannot complete the lifecycle period for an instance in the Pending:Wait state.
Option B is CORRECT because in the script, the complete-lifecycle-action command should be used to finish the lifecycle action before the timeout period ends.
The following is an example:
"aws autoscaling complete-lifecycle-action --lifecycle-hook-name my-lifecycle-hook --auto-scaling-group-name my-auto-scaling-group --lifecycle-action-result CONTINUE --lifecycle-action-token bcd2f1b8-9a78-44d3-8a7a-4dd07d7cf635"
Option C is incorrect because the put-lifecycle-hook CLI command creates or updates a lifecycle hook for a specified Auto Scaling group.
It is unsuitable to be used in this scenario.
Option D is incorrect because the AWS CLI command attach-instances attaches EC2 instances to the ASG.
It cannot finish the custom actions in a lifecycle hook.
Reference:
https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html, https://docs.aws.amazon.com/cli/latest/reference/autoscaling/complete-lifecycle-action.html.When you create a lifecycle hook in an Auto Scaling group, it allows you to put instances in a wait state until specific actions are performed. In this case, the wait state is required until the custom script in the user data completes its installation of the web application, initializes customer data, and passes a health check.
Once the health check has passed, you need to put the instance back to the InService state in the Auto Scaling group. The process for doing so depends on the implementation you have chosen. Here are the options provided in the answers:
A. Use the record-lifecycle-action-heartbeat CLI command or the RecordLifecycleActionHeartbeat operation in the script.
The record-lifecycle-action-heartbeat CLI command or the RecordLifecycleActionHeartbeat operation in the script is used to inform the Auto Scaling group that the instance is still in the wait state and to extend the timeout period if needed. This option is not relevant to putting the instance back to the InService state.
B. In the script, use the AWS CLI command complete-lifecycle-action to finish the lifecycle hook customer actions.
The complete-lifecycle-action CLI command is used to inform the Auto Scaling group that the instance has completed the lifecycle hook's custom actions and can be moved to the next state. This is the recommended option to put the instance back to the InService state.
C. Use the AWS CLI command put-lifecycle-hook to complete the lifecycle actions and put the instance back to the normal process of the Auto Scaling group.
The put-lifecycle-hook CLI command is used to create a new lifecycle hook or modify an existing one in the Auto Scaling group. This option is not relevant to putting the instance back to the InService state.
D. In the script, use the AWS CLI command attach-instances to attach the instance to the ASG, which completes the lifecycle action and modifies the instance state from Wait to InService.
The attach-instances CLI command is used to add instances to the Auto Scaling group. This option is not relevant to putting the instance back to the InService state.
In summary, the recommended option to put the instance back to the InService state in the Auto Scaling group is to use the complete-lifecycle-action CLI command in the script.