I'm getting this error when running a task on my Amazon Fargate cluster. Has anyone seen run into this before?
-
looks like you've mistyped `http` as `htt` in your repo, most likely – MrDuk Jan 31 '18 at 16:31
-
https://github.com/aws/amazon-ecs-agent/issues/1128 possibly this one can help – user2105282 Feb 27 '18 at 14:54
-
2I'm also working through this...it's not a typo @MrDuk it's just that they truncate the log in the ECS console – Mr.Budris Apr 05 '18 at 16:23
-
1Austin, have you found a resoultion for this? I'm trying to solve the same thing -- all SGs are correct, routing to a NAT instance is correct, etc etc – Mr.Budris Apr 05 '18 at 16:24
-
Related: [AWS Fargate - CannotPullContainerError (500)?](https://stackoverflow.com/q/48226547/55075) – kenorb Mar 27 '19 at 12:28
7 Answers
Go to the docs for an answer to this one.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_cannot_pull_image.html
Since you are encountering a 500
error, I would heed the advice of the first error's description, "Connection timed out":
When a Fargate task is launched, its elastic network interface requires a route to the internet to pull container images. If you receive an error similar to the following when launching a task, it is because a route to the internet does not exist:
CannotPullContainerError: API error (500): Get https://111122223333.dkr.ecr.us-east-1.amazonaws.com/v2/: net/http: request canceled while waiting for connection
To resolve this issue, you can:
For tasks in public subnets, specify ENABLED for Auto-assign public IP when launching the task...
For tasks in private subnets, specify DISABLED for Auto-assign public IP when launching the task, and configure a NAT Gateway in your VPC to route requests to the internet...
If you encountering any other issues relating to ECS Tasks not starting or exhibiting weird behavior upon starting, then check the full list of ECS troubleshooting topics.
I was encountering a similar error (404
instead of 500
), however, the Task displayed that it was RUNNING even though the detailed status listed an error.
It turns out that the role associated with the task (same role as the EC2 Instance on which it was running, in this case) could not be assumed by ecs-tasks. Adding the following trust relationship statement to the role resolved the issue:
{
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
See the specific page on the Task Execution Roles for more details.
Assigning a Public IP is mandatory for Fargate. For details see https://github.com/aws/amazon-ecs-agent/issues/1128
-
1I believe the Fargate launch type does not require assignment of Public IPs. Under "Task Networking Considerations" of [this Doc page](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-networking.html) it says, "You can configure [Fargate launch type] tasks to receive public IP addresses", implying that it is optional. This would make sense if you want to deploy a task in a private subnet of a vpc (using the 'awsvpc' network mode). – Tim Klein Nov 15 '18 at 15:27
Public IP is not mandatory, the specification for creating a working NAT Gateway is lacking. At the GitHub issue Amazon technicians keep repeating you "just" need Private IP + NAT, however this is not true. I struggled with this myself a lot, but finally got it working properly without using a Public IP for my Fargate services.
To have Fargate services access internet without having a Public IP you need to set up a VPC which has 2 subnets:
- A public subnet with an Internet Gateway allowing bidirectional internet access
- A private subnet with a NAT Gateway allowing only outgoing internet access
You can create such a VPC in 2 ways: by going to Services
> VPC
> VPC Dashboard
, clicking on Launch VPC Wizard
and selecting "VPC with Public and Private Subnets"
; or manually:
NOTE: All of the following steps are performed in Services
> VPC
- Go to
Your VPCs
andCreate a VPC
- Go to
Subnets
andCreate subnet
2 timesprivate
subnet- Attach it to the VPC in focus. Whatever CIDR block, whatever availability zone you like
public
subnet- Attach it to the VPC in focus. Whatever CIDR block, whatever availability zone you like
- Go to
Internet Gateways
andCreate internet gateway
- Name it however you want
- Select the newly created
Internet Gateway
,Actions
,Attach to VPC
and attach it to the VPC in focus
- Go to
NAT Gateways
andCreate NAT Gateway
- Important: Select the
public
subnet Create New EIP
or use an existing one given that you have one- Wait for the gateway to become
Available
- Important: Select the
- Go to
Route Tables
andCreate route table
2 timesprivate
route table- Attach it to the VPC in focus
- Back at the list, select the route table
Routes
tab on the bottom,Edit routes
Add route
, destination:0.0.0.0/0
, target the NAT Gateway created previously andSave routes
- Still having the route table selected,
Actions
andSet Main Route Table
(if not already)
public
route table- Attach it to the VPC in focus
- Back at the list, select the route table
Routes
tab on the bottom,Edit routes
Add route
, destination:0.0.0.0/0
, target the Internet Gateway created previously andSave routes
Subnet Associations
tab on the bottom,Edit subnet associations
- Select the
public
subnet,Save
- Put cucumber on eyes.
Every service you put in the public
subnet will have bidirectional internet access and every service you put in the private
subnet will have only outgoing internet access (yes, Fargate and EC2 services in the private
subnet without Public IPs will have internet access).

- 706
- 9
- 21
This error occurs when the container is unable to pull the container from the registry.
- Check that you're allocating a public IP address to your containers. Currently the AWS container registry doesn't have an internal-in-vpn endpoint.
- Check that your containers have a way to connect to the internet (eg: nat instance or similar.
- Check that the security group that you have associated with the container allows outbound traffic. If you created the SG with terraform or similar you may find that it's defaulting to having no outbound rules.

- 284
- 2
- 8
You have to allocate a Public Ip to your service, you can do it during the Service definition but as far as I know you can not update your service from the update menu.

- 225
- 1
- 7
If you are running ECS in a private VPC without Internet access, set up a VPC endpoint for ECR and S3 first.

- 6,254
- 5
- 53
- 70

- 467
- 4
- 8
Make sure that your subnet has access to the internet. In my case, the fargate task was deployed to a private subnet. While this subnet had the nat gateway configured, the public subnet, did not have a route to the internet gateway.

- 4,003
- 1
- 26
- 29