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.
ERROR: Service:AmazonECS, Message: Task failed to start
ERROR: Essential container in task exited
ERROR: CannotPullContainerError: image not foundCommon 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
- Open the ECS cluster behind the environment and view the stopped task.
- Read the stopped reason and the container exit code or pull error.
- 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.
{ "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.