Skip to content
Latchkey

Elastic Beanstalk "Service:AmazonECS" task failed (multi-container) in CI

The multi-container Docker platform runs your containers as an ECS task. When ECS cannot place or start the task (an essential container exits, the image fails to pull), Beanstalk surfaces a Service:AmazonECS error and the deploy fails.

What this error means

eb deploy fails with environment events mentioning "Service:AmazonECS" such as "ECS task stopped" or "Essential container in task exited", and the environment goes to a degraded state.

eb
ERROR: Service:AmazonECS, Message: Task failed to start
ERROR: Essential container in task exited
ERROR: CannotPullContainerError: image not found

Common causes

An essential container exits or the image cannot be pulled

If an essential container in the ECS task crashes on start, or the image reference is wrong/inaccessible, ECS stops the task and the deploy fails.

Insufficient task resources for placement

The Dockerrun task requests more memory or CPU than the instance type offers, so ECS cannot place the task on the environment instances.

How to fix it

Read the ECS stopped-task reason

  1. Open the ECS cluster behind the environment and view the stopped task.
  2. Read the stopped reason and the container exit code or pull error.
  3. Fix the image reference or container command and redeploy.

Right-size the container definitions

Set memory/cpu in Dockerrun.aws.json so the task fits the instance type, and use a reachable image reference.

Dockerrun.aws.json
{ "containerDefinitions": [
  { "name": "web", "image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/app:latest",
    "memory": 512, "essential": true } ] }

How to prevent it

  • Verify image references and registry access before deploy.
  • Size container memory/cpu to the environment instance type.
  • Make non-critical containers non-essential where appropriate.

Frequently asked questions

What causes ""Service:AmazonECS" task failed"?
If an essential container in the ECS task crashes on start, or the image reference is wrong/inaccessible, ECS stops the task and the deploy fails.
How do I fix "Service:AmazonECS" task failed?
Read the ECS stopped-task reason

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card