ECS Capacity Providers
In this post, I will discuss the capacity providers available in AWS ECS, supported types, scaling and other aspects.
Capacity provider is one of the compute options, you can configure to run the ECS tasks or services.
If you specify “launch type” as the compute option, your tasks are launched directly, on either Fargate or on the Amazon EC2 instances that are registered to your clusters.
Its difficult to maintain the infrastructure and the scaling aspect with the launch type, specially in case of EC2 instances. Capacity providers provide a more efficient approach to achieve this.
As per ECS, the main idea with the capacity provider is to shift the operational burden of compute away from the developers, and enable them to focus on the application first.
Capacity Providers Types
ECS supports three types of capacity providers — fargate, fargate spot and ec2 instances.
EC2 is the elastic compute provided by AWS. Fargate provides the serverless compute platform to run containers.
Fargate Spot uses spare capacity in the AWS cloud to run ECS tasks. When the capacity for Fargate Spot is available, you will be able to launch tasks based on your specified request. When AWS needs the capacity back, tasks running on Fargate Spot will be interrupted and stopped.
As your tasks could be interrupted, you should only run the tasks on Fargate Spot which can tolerate interruptions. For instance the batch application, which can restart from the last point of failure.
Creating Capacity Provider
Fargate Capacity Provider
Fargate and Fargate Spot capacity providers are created by ECS on your behalf. You just have to set the fargate flag as true for it.
On the console, I can just select the fargate type, or in our CDK code, I can just set the flag
enableFargateCapacityProviders as true. And you will see the Fargate and Fargate spot capacity providers are automatically created for you.