Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

A Python script for Lambda which launches on the termination of an ec2 instance to run shell commands on dying instances.

Notifications You must be signed in to change notification settings

hgranillo/aws-lambda-autoscaling-group-terminate-run-commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Run shell commands on autoscaling terminate action

Quick and dirty python script for running shell commands on instances flaged for termination on autoscaling groups using AWS SSM service.

Can be used for uploading your logs to an s3 bucket.

How to install

  • Add a hook on your autoscaling group, aws autoscaling put-lifecycle-hook --lifecycle-hook-name send-logs-hook --auto-scaling-group-name your-ag-group --heartbeat-timeout 60 --lifecycle-transition autoscaling:EC2_INSTANCE_TERMINATING
  • Create a function in lambda with the contents of script.py
  • Create events and rules on Cloudwatch that triggers this lambda function

Disclaimer

This worked for me, maybe there is a better way to do this. For instance, maybe I should create a SNS queue for this hook and add a notification endpoint to the put-lifecycle-hook command.

About

A Python script for Lambda which launches on the termination of an ec2 instance to run shell commands on dying instances.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages