![Autoscaling solution for Amazon ECS Cluster](https://assets.community.aws/a/2dEtKTxpFyFL1CBsYnte5Apd5vQ/1-jpg.webp)
Autoscaling solution for Amazon ECS Cluster
Explore autoscaling solution for Amazon ECS, unveiling strategies and best practices for seamless cluster adaptation to varying workloads.
What is challenging when it comes to autoscaling?
ECS Fargate cluster under the hood
So… how to autoscale this beast?
Let’s collect requirements for autoscaling solution
Collecting information (metrics) about sessions that are active in specific task
AWS Step Functions as an autoscaling executor
Assignment of infrastructure elements to test types
Unit tests of the Lambda function
Integration tests of the autoscaling infrastructure
E2E tests of the autoscaling infrastructure
CI/CD and the autoscaling solution
![AWS ECS Fargate AWS ECS Fargate](https://assets.community.aws/a/2dEtp7wb3UuHw0os1AKB97lRhVR/2-pn.webp)
![Stateful ECS workload Stateful ECS workload](https://assets.community.aws/a/2dEtsoGBKGTMk1rGS4e2CWDOlM6/3-pn.webp)
![ECS Fargate cluster under the hood ECS Fargate cluster under the hood](https://assets.community.aws/a/2dEtvDhP9crbYIUR3D29axEKtUp/4-pn.webp)
![Scaling up of the ECS cluster Scaling up of the ECS cluster](https://assets.community.aws/a/2dEtxISIv8hT7fFCDqaWvlmOsjr/5-pn.webp)
![ECS cluster cost ECS cluster cost](https://assets.community.aws/a/2dEtzC704nGI4bajmSy9RTBrF8s/6-jpe.webp)
![Private API Gateway with DynamoDB to collect metrics Private API Gateway with DynamoDB to collect metrics](https://assets.community.aws/a/2dEu226QF4ODoaGb7eMRJHnmSW4/7-pn.webp)
![Example metric sent from the app Example metric sent from the app](https://assets.community.aws/a/2dEu3LqLZmpKnAU8DG5hGHvdLQI/8-pn.webp)
![Reading cluster’s utilization from CloudWatch and combining it with activity of Sessions in cluster’ Reading cluster’s utilization from CloudWatch and combining it with activity of Sessions in cluster’](https://assets.community.aws/a/2dEu5ZfHyNGS6noAoJAaq1lCuPq/9-pn.webp)
- Deregister specific Task from Load balancer’s targets,
- Wait for it to be deregistered from the Load balancer,
- Stop this task in the ECS’s Service,
- Remove it from the ECS’s Service.
![Logic for scaling operation Logic for scaling operation](https://assets.community.aws/a/2dEuCcCDMPsaMKLboQSpejcptD8/10-p.webp)
![AWS Step Functions as autoscaling executor for ECS cluster AWS Step Functions as autoscaling executor for ECS cluster](https://assets.community.aws/a/2dEu9dlhNqpNV5UGpjS3cI9TktL/11-p.webp)
![AWS Step Functions ECS’s autoscaler definition AWS Step Functions ECS’s autoscaler definition](https://assets.community.aws/a/2dEuFXpemaP1aiY78q5xEQRBeWD/12-p.webp)
![Execution parameters needed to scale out the cluster Execution parameters needed to scale out the cluster](https://assets.community.aws/a/2dEuJmMAHKIJ0m088YT6EhGo5TM/13-p.webp)
![Execution parameters needed to scale in the cluster Execution parameters needed to scale in the cluster](https://assets.community.aws/a/2dEuLinSmsoP3taziigPGJDU6TQ/14-p.webp)
Everything Fails All the Time
![Testing pyramid Testing pyramid](https://assets.community.aws/a/2dEuOPhn5YmIOpRziX4ecX800k4/15-p.webp)
- Unit tests, focusing on testing the smallest possible fragments of software (especially in terms of code) in simulated conditions,
- Integration tests, focusing on checking the behaviour of individual infrastructure elements correlating between themselves,
- E2E tests that check the behaviour of the entire service in conditions that are the most similar to real life.
![E2E, Integration and Unit tests of cloud infrastructure E2E, Integration and Unit tests of cloud infrastructure](https://assets.community.aws/a/2dEuSOkknvsd1bwt6HwqOQFOkoC/16-p.webp)
![Mocked boto3 responses Mocked boto3 responses](https://assets.community.aws/a/2dEuV76SPoJgSraKkkER2Nt23HG/17-p.webp)
![Integration tests of the AWS Step Functions using another AWS Step Functions Integration tests of the AWS Step Functions using another AWS Step Functions](https://assets.community.aws/a/2dEuaW1Uf2kkVmBvBTL5faUrxCi/19-p.webp)
![AWS Step Functions which calls another AWS Step Functions AWS Step Functions which calls another AWS Step Functions](https://assets.community.aws/a/2dEuiEhpF5v0vZLdJP05Z1fu2qJ/20-p.webp)
- Disabling the cluster state analyzer,
- Preparing the cluster, launching the appropriate number of tasks,
- Creating a test scenario (e.g. scale the cluster down to 1 task),
- Sending the scenario to Testing Step Function, which tests the cluster’s behavior,
- Waiting for the result.
![E2E tests of ECS autoscaling solution E2E tests of ECS autoscaling solution](https://assets.community.aws/a/2dEuk3nITM7MriMJDqsEruwKrFg/21-p.webp)
![CI/CD for AWS CDK projects with unit, integration and e2e tests CI/CD for AWS CDK projects with unit, integration and e2e tests](https://assets.community.aws/a/2dEulys0CSWVzqyvDBYVFdbu5yd/22-p.webp)
![AWS Step Functions – Redrive AWS Step Functions – Redrive](https://assets.community.aws/a/2dEunw110PGLh3QYGpmWrTkkM0e/23-p.webp)
![4Developers – Łódź 2023 4Developers – Łódź 2023](https://assets.community.aws/a/2dEuvB3DLHkNgUoeJ3ZngjiSeKe/24-jpg.webp)