Skip to content

chafouin/aws-asg-lifecycle-hook-handler

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

AWS AutoScaling lifecycle hook handler

This script can be use to react on an Autoscaling group lifecycle hook, it is useful if you need to stop the instance processing before teminating it, in a graceful manner. See AWS documentation for more information on lifecycle hook. When the termination hook is pending, the autoscaling group will wait a certain amount of time for a signal to release the hook and terminate the instance. The script will check the hook and if it is pending, it will run the given command and wait for it to finish. During the execution time, it will periodically send an heartbeat signal to avoid the hook to time out. After the command execution, the script will release the hook and the instance will be terminated by the ASG.

Requirements

  • Python 3.4+
  • Pipenv

Usage

$ ./lifecycle_hook_handler.py -h
usage: lifecycle_hook_handler.py [-h] [-r REGION] -c COMMAND -l LIFECYCLEHOOK
                                 -g AUTOSCALINGGROUP [-a ACTIONRESULT]
                                 [-b HEARTBEAT] [-d]

Script to execute given command when receiving a AutoScaling lifecycle hook

optional arguments:
  -h, --help            show this help message and exit
  -r REGION, --region REGION
                        AWS region
  -c COMMAND, --command COMMAND
                        Command to run
  -l LIFECYCLEHOOK, --lifecyclehook LIFECYCLEHOOK
                        Lifecycle hook name
  -g AUTOSCALINGGROUP, --autoscalinggroup AUTOSCALINGGROUP
                        Autoscaling group name
  -a ACTIONRESULT, --actionresult ACTIONRESULT
                        Lifecycle hook result: ABANDON or CONTINUE
  -b HEARTBEAT, --heartbeat HEARTBEAT
                        Heartbeat rate in seconds
  -d, --debug           Debug mode

License

GNUv3 Licence

About

Run a command on an EC2 instance when an AutoScaling lifecycle hook status changes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published