AWS – Auto Scaling Lifecycle Hooks

Auto Scaling lifecycle hooks enable you to perform custom actions as Auto Scaling launches or terminates instances. For example, you could install or configure software on newly launched instances, or download log files from an instance before it terminates.

  • Create a lifecycle hooks to perform an action on scale out
$ aws autoscaling put-lifecycle-hook —lifecycle-hook-name my-hook --auto-scaling-group-name my-asg --lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING
  • Create a lifecycle hooks to perform an action on scale in
$ aws autoscaling put-lifecycle-hook —lifecycle-hook-name my-hook --auto-scaling-group-name my-asg --lifecycle-transition autoscaling:EC2_INSTANCE_TERMINATING
  • If you need more time than 1 hour send a heartbeat to keep the current state of the instance.
$ aws autoscaling record-lifecycle-action-heartbeat --instance-id i-1a2b3c4d5e6f7g --lifecycle-hook-name my-launch-hook --auto-scaling-group-name my-asg
  • Put the instance on InService state
$ aws autoscaling complete-lifecycle-action —lifecycle-action-result CONTINUE —instance-id i-1a2b3c4d5e6f7g —lifecycle-hook-name my-hook —auto-scaling-group-name my-asg
  • Put the instance on terminate state
$ aws autoscaling complete-lifecycle-action —lifecycle-action-result TERMINATE —instance-id i-1a2b3c4d5e6f7g —lifecycle-hook-name my-hook --auto-scaling-group-name my-asg
You can read more about Auto Scaling Lifecycle Hooks here.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.