I was learning about lifecycle hooks recently. Before I added my own, I thought I'd do some research in the lifecycle hooks available. I was hoping to find a simple terraform module lambda for ECS. After some searching, I curated this list and thought "Why not another awesome list?" And the list was born.
Feel free to contribute.
Repo | Resources | Provisioner |
---|---|---|
getsocial-rnd/ecs-drain-lambda | cloudwatch event, golang lambda | sls, terraform |
ericdahl/tf-ecs | cloudwatch event, sns, python lambda | terraform |
terraform-community-modules/tf_aws_ecs_instance_draining_on_scale_in | terraform | |
ktruckenmiller/aws-ecs-spot-instance-drainer | cloudformation | |
cloudwatch event, sns, python lambda | terraform | |
btisdall/ecs-cid | ||
docker-production-aws/lambda-lifecycle-hooks | ||
claranet/terraform-aws-ecs-container-instances | cloudwatch event, sqs, python lambda | terraform |
aws-samples/ecs-cid-sample | cloudwatch event, sns, python lambda | cloudformation |
- aws-samples/aws-lambda-lifecycle-hooks-function - backup data to s3 using sns and lambda
Condition | Invoked? |
---|---|
Spot interruption | Yes |
EC2 instance degradation | Yes |
ASG instance refresh | Yes |
ASG max instance lifetime | Yes |
EC2 manual termination from CLI | Yes |
EC2 manual termination from UI | No |
# set variables
INSTANCE_ID=i-aaaabbbbcccc
ASG_NAME=asg-xyz
LIFECYCLE_HOOK_NAME=lifecycle-xyz
# terminate a specific instance id
aws autoscaling \
terminate-instance-in-auto-scaling-group \
--should-decrement-desired-capacity \
--instance-id $INSTANCE_ID
# once the instance is in a Terminating:Wait stage, continue the lifecycle
aws autoscaling \
complete-lifecycle-action \
--lifecycle-action-result CONTINUE \
--lifecycle-hook-name $LIFECYCLE_HOOK_NAME \
--auto-scaling-group-name $ASG_NAME \
--instance-id $INSTANCE_ID
References
- How do I delay Auto Scaling termination of unhealthy Amazon EC2 instances so I can troubleshoot them?
- aws autoscaling terminate-instance-in-auto-scaling-group
- aws autoscaling complete-lifecycle-action
- 24 Dec 2021 - Sending EC2 logs to S3 via lifecycle hooks - great explanation and diagrams
- 03 Sep 2020 - Graceful shutdown using AWS Auto Scaling groups and Terraform
- 04 Oct 2019 - Autoscaling like a pro: how to use EC2 Auto Scaling Lifecycle Hooks, the right way.
- 22 Sep 2019 - Scale down a Kube Cluster Minion without Downtime using AWS Autoscaling Lifecycle Hook — Part III
- 24 Sep 2018 - AWS Auto Scaling Group: Working With Lifecycle Hooks
- 05 Jun 2018 - Amazon EC2 Auto Scaling lifecycle hooks to Export Instance Logs After Marked For Terminate
- 16 May 2018 - AWS Auto Scaling Lifecycle
- 25 Jan 2017 - How to Automate Container Instance Draining in Amazon ECS
- 04 Nov 2015 - Under the Hood: AWS CodeDeploy and Auto Scaling Integration
- 20 Jan 2015 - Deep Dive Into Auto Scaling Lifecycle Hooks