AWS Fargate capacity providers - Amazon Elastic Container Service

AWS Fargate capacity providers

With Amazon ECS on AWS Fargate capacity providers, you can use both Fargate and Fargate Spot capacity with your Amazon ECS tasks.

With Fargate Spot, you can run interruption tolerant Amazon ECS tasks at a rate that's discounted compared to the Fargate price. Fargate Spot runs tasks on spare compute capacity. When AWS needs the capacity back, your tasks are interrupted with a two-minute warning.

Fargate capacity provider considerations

Consider the following when using Fargate capacity providers:

  • Windows containers on Fargate don't support the Fargate Spot capacity provider.

  • Linux tasks with the ARM64 architecture don't support the Fargate Spot capacity provider. Fargate Spot only supports Linux tasks with the X86_64 architecture.

  • You don't need to create Fargate and Fargate Spot capacity providers. They're available to all accounts. To use them, all you need to do is associate them with a cluster.

  • To associate Fargate and Fargate Spot capacity providers to a cluster, you must use the Amazon ECS API or AWS CLI. You cannot associate them using the console.

  • The Fargate and Fargate Spot capacity providers are reserved and can't be deleted. However, you can disassociate them from a cluster using the PutClusterCapacityProviders API operation.

  • You can associate a capacity provider with an existing cluster using the PutClusterCapacityProviders API operation.

  • If you use Fargate Spot, your task must use platform version 1.3.0 or later (for Linux). For more information, see Fargate Linux platform versions.

  • When tasks that use the Fargate and Fargate Spot capacity providers are stopped, the task state change event is sent to Amazon EventBridge. The stopped reason describes the cause. For more information, see Task state change events.

  • A cluster can contain a mix of Fargate and Auto Scaling group capacity providers. However, a capacity provider strategy can only contain either Fargate or Auto Scaling group capacity providers, but not both. For more information, see Auto Scaling Group Capacity Providers in the Amazon Elastic Container Service Developer Guide.

Handling Fargate Spot termination notices

Understand that the following consequences because Spot capacity might not be available all the time.

  • During periods of extremely high demand, Fargate Spot capacity might be unavailable. This can cause Fargate Spot tasks to be delayed. In these events, Amazon ECS services retry launching tasks until the required capacity becomes available. Fargate doesn't replace Spot capacity with on-demand capacity.

  • When tasks using Fargate Spot capacity are stopped due to a Spot interruption, a two-minute warning is sent before a task is stopped. The warning is sent as a task state change event to Amazon EventBridge and as a SIGTERM signal to the running task. If you use Fargate Spot as part of a service, then in this scenario the service scheduler receives the interruption signal and attempts to launch additional tasks on Fargate Spot if there's capacity available. A service with only one task is interrupted until capacity is available. For more information about a graceful shutdown, see Graceful shutdowns with ECS .

To ensure that your containers exit gracefully before the task stops, you can configure the following:

  • A stopTimeout value of 120 seconds or less can be specified in the container definition that the task is using. The default stopTimeout value is 30 seconds. You can specify a longer stopTimeout value to give yourself more time between the moment that the task state change event is received and the point in time when the container is forcefully stopped. For more information, see Container timeouts.

  • The SIGTERM signal must be received from within the container to perform any cleanup actions. Failure to process this signal results in the task receiving a SIGKILL signal after the configured stopTimeout and may result in data loss or corruption.

The following is a snippet of a task state change event. This snippet displays the stopped reason and stop code for a Fargate Spot interruption.

{ "version": "0", "id": "9bcdac79-b31f-4d3d-9410-fbd727c29fab", "detail-type": "ECS Task State Change", "source": "aws.ecs", "account": "111122223333", "resources": [ "arn:aws:ecs:us-east-1:111122223333:task/b99d40b3-5176-4f71-9a52-9dbd6f1cebef" ], "detail": { "clusterArn": "arn:aws:ecs:us-east-1:111122223333:cluster/default", "createdAt": "2016-12-06T16:41:05.702Z", "desiredStatus": "STOPPED", "lastStatus": "RUNNING", "stoppedReason": "Your Spot Task was interrupted.", "stopCode": "SpotInterruption", "taskArn": "arn:aws:ecs:us-east-1:111122223333:task/b99d40b3-5176-4f71-9a52-9dbd6fEXAMPLE", ... } }

The following is an event pattern that's used to create an EventBridge rule for Amazon ECS task state change events. You can optionally specify a cluster in the detail field. Doing so means that you will receive task state change events for that cluster. For more information, see Creating an EventBridge Rule in the Amazon EventBridge User Guide.

{ "source": [ "aws.ecs" ], "detail-type": [ "ECS Task State Change" ], "detail": { "clusterArn": [ "arn:aws:ecs:us-west-2:111122223333:cluster/default" ] } }