Amazon ECS clusters and capacity - Amazon Elastic Container Service

Amazon ECS clusters and capacity

An Amazon ECS cluster is a logical grouping of tasks or services. In addition to tasks and services, a cluster consists of the following resources:

  • The infrastructure capacity which can be a combination of the following:

    • Amazon EC2 instances in the AWS cloud

    • Serverless (AWS Fargate (Fargate)) in the AWS cloud

    • On-premises virtual machines (VM) or servers

  • The network (VPC and subnet) where your tasks and services run

    When you use Amazon EC2 instances for the capacity, the subnet can be in Availability Zones, Local Zones, Wavelength Zones or AWS Outposts.

  • An optional namespace

    The namespace is used for service-to-service communication with Service Connect.

  • A monitoring option

    CloudWatch Container Insights comes at an additional cost and is a fully managed service. It automatically collects, aggregates, and summarizes Amazon ECS metrics and logs.

Capacity provider concepts

Capacity providers consist of the following components.

Capacity provider

A capacity provider defines the cluster capacity that Amazon ECS scales up and down of the infrastructure you specify. You must first associate the capacity provider with a cluster before you use the capacity provider.

You use a capacity provider in a capacity provider strategy to determine the infrastructure that a task runs on. Every task must have a capacity provider strategy, a launch type, or use the default capacity provider strategy that's associated with the selected cluster. You must reference the capacity provider strategy and not the capacity provider. If a task uses a launch type, the capacity it uses isn't counted by any capacity providers in the cluster.

For AWS Fargate, the capacity providers are a FARGATE and a FARGATE_SPOT capacity provider which AWS creates. You associate the capacity provider with your cluster, and then add them to a capacity provider strategy.

For Amazon ECS on Amazon EC2 users, a capacity provider consists of a capacity provider name, an Auto Scaling group. A capacity provider also consists of all of the settings for managed scaling and managed termination protection. When you turn on managed scaling, Amazon ECS scales Auto Scaling groups in and out on your behalf.

Default capacity provider strategy

You can associate a default capacity provider strategy with an Amazon ECS cluster. After you do this, Amazon ECS uses a default capacity provider strategy when you create service or run a standalone task in the cluster and don't specify a launch type or custom capacity provider. We recommend that you define a default capacity provider strategy for each cluster.

Capacity provider strategy

A capacity provider strategy consists of one or more capacity providers. You can specify an optional base and weight value for finer control. A capacity provider strategy is part of the configuration of a cluster, service, or task. However, you can't create re-useable capacity provider strategies. The capacity provider strategy of each cluster, service, or task capacity provider strategy is independent.

If the default capacity provider strategy for a cluster doesn't meet your capacity requirements, specify a custom capacity provider strategy when creating a service or running a standalone task.

Important

When you set a launch type instead of a capacity provider strategy on tasks in clusters where the capacity is managed by capacity providers, those tasks aren't counted for capacity provider scaling actions.

Only capacity providers that are both already associated with a cluster and have an ACTIVE or UPDATING status can be used in a capacity provider strategy. You can associate a capacity provider with a cluster when you create a cluster.

In a capacity provider strategy, the optional base value designates how many tasks, at a minimum, run on a specified capacity provider. Only one capacity provider in a capacity provider strategy can have a base defined.

The weight value determines the relative percentage of the total number of launched tasks that use the specified capacity provider. Consider the following example. You have a strategy that contains two capacity providers, and both have a weight of 1. When the base percentage is reached, the tasks are split evenly across the two capacity providers. Using that same logic, suppose that you specify a weight of 1 for capacityProviderA and a weight of 4 for capacityProviderB. Then, for every one task that's run using capacityProviderA, there are four tasks that use capacityProviderB.