Skip to content
Run a command on an EC2 instance when an AutoScaling lifecycle hook status changes
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests
.gitignore Initial commit Nov 2, 2018
LICENSE Initial commit Nov 2, 2018
Pipfile
Pipfile.lock Initial commit Nov 2, 2018
README.md
lifecycle_hook_handler.py Initial commit Nov 2, 2018

README.md

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

You can’t perform that action at this time.