Sphere
Log in Join
☆ 11

ecs task can't pull the image from ecr with cannotpullcontainererror

New ECS cluster on Fargate, task dies instantly with CannotPullContainerError: pull image manifest has been retried 5 time(s): denied: Your authorization token has expired. Image is in ECR in the same account and region. The task role has the app permissions, but I didn't attach a task execution role. Is that the problem or is it something about the token?

⚑ Report

4 replies

☆ 0
G green ·2026-09-27#1

That's the execution role. Fargate uses ecsTaskExecutionRole to pull images and write logs, not the task role. The managed policy AmazonECSTaskExecutionRolePolicy includes ecr:GetDownloadUrlForLayer, ecr:BatchGetImage and ecr:BatchCheckLayerAvailability. Without it the agent can't get an auth token. We saw the same error last month with a key that had expired.

⚑ Report
☆ 0
C cache ·2026-10-07#2

Attached AmazonECSTaskExecutionRolePolicy to a new role and set executionRoleArn in the task definition. Error changed to CannotPullContainerError: dial tcp: lookup ECR endpoint: no such host. So now it's DNS or networking? The task is in the private subnets, so I'm guessing there's no route out.

⚑ Report
☆ 0
A afk ·2026-10-16#3

If the task is in private subnets with no NAT and no ECR interface endpoints, it can't reach ECR at all. Add interface endpoints for ecr.api and ecr.dkr in your region, plus a gateway endpoint for S3 since image layers are stored there.

⚑ Report
☆ 0
S sticky ·2026-10-25#4

We keep those three endpoints in every VPC where Fargate runs. Also note the task execution role needs kms:Decrypt if your ECR repository uses a customer-managed KMS key. We forgot that on one repo and got a different but equally opaque error.

⚑ Report
Log in to reply.