ECS Container Instance scale-in protector
Protect container instance with containers running from scale-in. Uses aws-cli set-instance-protection. Inspired by: https://stackoverflow.com/questions/45020323/ecs-asg-scaling-down-policy-recommendations
Ignores ecs-agent and dd-agent when counting running containers. You can add more in containers_running
in the script below.
Prerequisites
- awk
- awscli
- run as root
- cron (opt.)
- Permissions for EC2 IAM role
- autoscaling:DescribeAutoScalingInstances
- autoscaling:SetInstanceProtection
Example crontab
*/5 * * * * root /usr/local/bin/scale_in_protection.sh