Amazon ECS cluster auto scaling - Amazon Elastic Container Service

Amazon ECS cluster auto scaling

Amazon ECS can manage the scaling of Amazon EC2 instances that are registered to your cluster. This is referred to as Amazon ECS cluster auto scaling. This is done by using an Amazon ECS Auto Scaling group capacity provider with managed scaling turned on. When you use an Auto Scaling group capacity provider with managed scaling turned on, you set a target percentage (the targetCapacity) for the utilization of the instances in this Auto Scaling group. Amazon ECS creates two custom CloudWatch metrics and a target tracking scaling policy that attaches to your Auto Scaling group. Amazon ECS then manages the scale-in and scale-out actions of the Auto Scaling group based on the resource utilization that your tasks use from this capacity provider. For more information about Auto Scaling group capacity providers, see Amazon EC2 Auto Scaling group capacity providers.

Note

Amazon ECS cluster auto scaling is only supported with Auto Scaling group capacity providers. For Amazon ECS workloads that are hosted on AWS Fargate, see AWS Fargate capacity providers.

The following is your workflow to use Amazon ECS cluster auto scaling. For more information, see Turn on cluster auto scaling.

  1. Create an Auto Scaling group.

  2. Create a capacity provider that uses that Auto Scaling group.

  3. Turn on managed scaling for the capacity provider.

  4. Associate the capacity provider with a cluster.

  5. Run a task or create a service with a capacity provider strategy that uses the capacity provider.

    The capacity provider strategy determines how the tasks are spread across the cluster's capacity providers. When you run a standalone task or create a service, you either use the cluster's default capacity provider strategy or a capacity provider strategy that overrides the default one.

  6. (Optional) Create a default capacity provider strategy for the cluster.

As of May 27, 2022, Amazon ECS no longer creates an AWS Auto Scaling scaling plan for newly created capacity providers. Instead, Amazon ECS uses the target tracking scaling policy attached to the Auto Scaling group to perform dynamic scaling based on your target capacity specification. For more information, see Amazon EC2 Auto Scaling group capacity providers.

With this new release, you can use an existing Auto Scaling group with a scaling policy for use when creating a new capacity provider. We don't recommend that you modify the ECS managed scaling policy or plan resources. However, when creating new capacity provider resources, if you have customized tooling that made modifications to the AWS Auto Scaling scaling plan, do one of the following:

  • (Recommended) Update your capacity provider to modify the Amazon ECS managed scaling settings. For more information, see UpdateCapacityProvider.

  • Update the scaling policy associated with your Auto Scaling group to modify the target tracking configuration used. For more information, see PutScalingPolicy.

Considerations

Consider the following when using cluster auto scaling:

  • Don't change or manage the desired capacity for the Auto Scaling group that's associated with a capacity provider with any scaling policies other than the one Amazon ECS manages.

  • Amazon ECS uses the AWSServiceRoleForECS service-linked IAM role for the permissions that it requires to call AWS Auto Scaling on your behalf. For more information about using and creating Amazon ECS service-linked IAM roles, see Using service-linked roles for Amazon ECS.

  • When using capacity providers with Auto Scaling groups, the user, group, or role that creates the capacity providers requires the autoscaling:CreateOrUpdateTags permission. This is because Amazon ECS adds a tag to the Auto Scaling group when it associates it with the capacity provider.

    Important

    Make sure any tooling that you use doesn't remove the AmazonECSManaged tag from the Auto Scaling group. If this tag is removed, Amazon ECS can't manage the scaling.

  • Cluster auto scaling doesn't modify the MinimumCapacity or MaximumCapacity for the group. For the group to scale out, the value for MaximumCapacity must be greater than zero.

  • When Auto Scaling (managed scaling) is turned on, a capacity provider can only be connected to one cluster at the same time. If your capacity provider has managed scaling turned off, you can associate it with multiple clusters.

  • When managed scaling is turned off, the capacity provider doesn't scale in or scale out. You can use a capacity provider strategy to balance your tasks between capacity providers.

  • The binpack strategy is the most efficient strategy in terms of capacity.

  • When the target capacity is less than 100%, the placement strategy needs to use the binpack strategy without the spread srategy having a higher order than the binpack strategy. This prevents the capacity provider from scaling out until each task has a dedicated instance or the limit is reached.

Consider the following when you use the console:

  • By default, the Amazon ECS managed scaling feature is on. For more information, see Managed scale-out behavior.

  • By default, managed termination protection is off. For more information, see the next section Managed termination protection.

  • By default, Auto Scaling instance scale-in protection is off. For more information, see Using instance scale-in protection in the Amazon EC2 Auto Scaling User Guide.

  • The Auto Scaling group that's used with your capacity provider can't use instance weighting settings. Instance weighting isn't supported when used together with an Amazon ECS capacity provider.