Autoscaling Services

Autoscaling is very important to making sure that your services stay online when traffic increases unexpectedly. In both EC2 and AWS Fargate one way to ensure your service autoscales is to increase and decrease the number of copies of your application container that are running in the cluster.

Autoscaling works like this:

ecs autoscaling

The following templates automatically setup CloudWatch alarms, autoscaling policies, and attach them to an ECS service.

Add autoscaling to your service

Use these templates:
Scale service up and down based on CPU usage Launch Download
Scale service up and down based on memory usage Launch Download

These templates try to keep their respective resource (CPU or memory) above 20% but below 70%. By default if the CPU or memory is at 70% - 85% they add one more container, if at 85% - 95% they add two containers, if above 95% they add three containers. If the CPU is less than 20% they stop a container. You can adjust the exact thresholds by downloading the template and adjusting the values within.