ECSCALE

A serverless app removing underutilized hosts from ECS clusters

Scaling ECS down is not a straightforward task;Based on one metric solely, an instance could be taken down causing 2 effects:

  1. Forcefully removing a host when a container is running will cut off active connections causing service downtime
  2. Removing an instance based on utilization / capacity metric may cause an endless loop of scale

To such an end, this tool will look for scaleable clusters based on multiple metrics

Once identified, the target is moved to "draining" state, where a new instance of the same task is raised on an available host. Once the new containers are ready, the draining instsnce will start draining connection from active tasks. Once the draining process is complete, the instance will be terminated.

Usage:

  1. Throw ecscale.py code to AWS Lambda providing relevant role to handle ECS and autoscaling (Instrcutions ahead)
  2. Set repeated run (recommended every 60 minutes using a cloudwatch events trigger for Lambda)
  3. That's it... Your ECS hosts are being gracefully removed if needed. No metrics/alarms needed

Changable Parameters:

How to create a role to run ecscale:
  1. When creating the Lambda function, you'll be asked to select a role or create a new one, choose a new role
  2. Provide the json from policy.json to the role policy
  3. All set to allow ecscale to do its work
Creating a Lambda function step by step:

Flow logic

Read about it some more on Medium