How do I troubleshoot an Amazon ECS RunTask API for a Fargate task that fails with a "Capacity is unavailable" error?

2 minute read
0

I want to use the Amazon Elastic Container Service (Amazon ECS) RunTask API to launch an AWS Fargate task. However, the task fails because of unavailable capacity.

Short description

If Amazon ECS doesn't have the capacity to launch a Fargate task, then the RunTask API fails with the following error message:

"Capacity is unavailable at this time. Please try again later or in a different availability zone"

To troubleshoot this error, wait before you retry the RunTask API. You can also use AWS Step Functions to automate the retry process.

Resolution

Retry the RunTask API at a later time.

The following practices might grant you more available capacity for RunTask and shorten your wait time:

  • Because Amazon ECS manages capacity by Availability Zone, it's a best practice to set multiple subnets in different Availability Zones in the networkConfiguration.awsvpcConfiguration.subnets RunTask request parameter.
  • Set the overrides.cpu and overrides.memory RunTask request parameters to different CPU and memory combinations. For more information, see Task CPU and memory.

Automate the RunTask API

To automate the initiation and subsequent retries of the RunTask API, use Step Functions.

If you start RunTask from Step Functions and the task fails because of limited capacity, then Step Functions records an ECS.AmazonECSException in its ErrorEquals field. You can use this information to configure future retries.

To set up a Step Function workflow, see Manage Amazon ECS or Fargate Tasks with Step Functions. For more information on Step Functions error reporting, see Error handling in Step Functions.

If you regularly call the RunTask API from Amazon EventBridge, then call Step Functions from EventBridge to automate your retries.

AWS OFFICIAL
AWS OFFICIALUpdated 6 months ago
2 Comments
  1. Check Fargate Cluster Capacity:

    • Verify sufficient resources in the Fargate cluster.
  2. Check Task Definition Resources:

    • Ensure task resource requirements are within cluster limits.
  3. Check Service Quotas:

    • Confirm Fargate resource quotas are not exceeded.
  4. Review Task Placement Constraints:

    • Ensure placement constraints allow task placement.
  5. Check VPC and Subnet Configuration:

    • Verify correct VPC and subnet settings.
  6. Update ECS Agent:

    • Ensure ECS agent on Fargate instances is up to date.
  7. Check for Service Events:

    • Review ECS service events for additional details.
  8. Check CloudWatch Logs:

    • Examine CloudWatch Logs for error messages.
  9. Review IAM Roles and Policies:

    • Confirm IAM roles have necessary permissions.
  10. Contact AWS Support:

    • If issues persist, seek assistance from AWS Support.
profile picture
replied 3 months ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied 3 months ago