ResourceInitializationError with AWS ECS deployment - amazon-web-services

I am deploying containers on ECS (fargate) with platform versions 1.4.0 (Latest) in the private subnet using GitHub action. I have routed the traffic through the NAT gateway and have the ECS task Execution role with the secret manager's full access policy. When I bind ECS service to only one private subnet then the containers getting deployed over ECS with no error, but once I bind two private subnets for making ECS service more available then the task gets stopped with an error below error.
ResourceInitializationError: unable to pull secrets or registry auth: execution resource retrieval failed: unable to retrieve secret from asm: service call has been retried 5 time(s): failed to fetch secret arn:aws:secretsmanager:ap-south-1:27XXXXX...
I have tried every possible solution mentioned here but none is worked for me.

Related

ECS can't pull ECR images

I have created an ECS service and started a service with a task definition.
I wan't the ability to start these services in a private subnet, but I read that for that to happen I need to use:
NAT Gateway
or
VPC Endpoints for S3 and ECR (API and DKR). Optional are Secret Manager and CLoudWatch
I don't want to to pay fir NAT Gateway so I started configuring the option with VPC endpoints.
I created:
ECR DKR and API Interface endpoints targeting the subnets that I use
S3 gateway endpoint attached to the route table of the subnet I am using
Secret Manager Interface endpoint (For future application using secrets)
CloudWatch interface endpoint for logging
I also attached the interface endpoints to a security group that has:
Ingress: 80 and 443 - 0.0.0.0/0
egress: All
enabled DNS support, hostnames and resolution on the VPC.
And created the correct ECS task execution and task role for the service with ecr and cloud watch permissions.
But regardless all of this configuration, I am getting this error when starting up the service:
Resourceinitializationerror: unable to pull secrets or registry auth: execution resource retrieval failed: unable to retrieve ecr registry auth: service call has been retried 3 time(s): RequestError: send request failed caused by: Post "https://api.ecr.eu-central-1.amazonaws.com/": dial tcp 52.119.188.80:443: i/o timeout
I don't know already what to do, I freaking out, I am trying to get the resolution for already few hours.
If someone knows how to fix it, I would appreciate that.
Thanks

Unable to connect to Redis External Load Balancer Service

I have created an EKS cluster with the Managed Node Groups.
Recently, I have deployed Redis as an external Load Balancer service.
I am trying to to set up an authenticated connection to it via NodeJS and Python microservices but I am getting Connection timeout error.
However, I am able to enter into the deployed redis container and execute the redis commands.
Also, I was able to do the same when I deployed Redis on GKE.
Have I missed some network configurations to allow traffic from external resources?
The subnets which the EKS node is using are all public.
Also, while creating the Amazon EKS node role, I have attached 3 policies to this role as suggested in the doc -
AmazonEKSWorkerNodePolicy
AmazonEC2ContainerRegistryReadOnly
AmazonEKS_CNI_Policy
It was also mentioned that -
We recommend assigning the policy to the role associated to the Kubernetes service account instead of assigning it to this role.
Will attaching this to the Kubernetes service account, solve my problem ?
Also, here is the guide that I used for deploying redis -
https://ot-container-kit.github.io/redis-operator/guide/setup.html#redis-standalone

ECS Fargate Task in EventBridge fails with ResourceInitializationError

I have created an ECS Fargate Task, which I can manually run. It updates a Dynomodb and I get logs.
Now I want this to run on a schedule. I have setup a scheduled ECS task through EventBridge. However, this does not run.
My looking at the EventBridge logs I can see that the container has been stopped for the following stopped reason:
ResourceInitializationError: unable to pull secrets or registry auth: execution resource
retrieval failed: unable to retrieve ecr registry auth: service call has been retried 3
time(s): RequestError: send request failed caused by: Post https://api.ecr....
I thought this might be a problem with permissions. However, I tested giving the Task Execution Role full power user permissions and I still get the same error. Could the problem be something else?
This is due to a connectivity issue.
The docs say the following:
For tasks on Fargate, in order for the task to pull the container image it must either use a public subnet and be assigned a public IP address or a private subnet that has a route to the internet or a NAT gateway that can route requests to the internet.
So you need to make sure your task has a route to an internet gateway (i.e. it's in a Public subnet) or a NAT gateway.
Alternatively, if your service is in an isolated subnet, you need to create VPC endpoints for ECR and other services you need to call, as described in the docs:
To allow your tasks to pull private images from Amazon ECR, you must create the interface VPC endpoints for Amazon ECR.
When you create a scheduled task, you also specify the networking options. The docs mention this step:
(Optional) Expand Configure network configuration to specify a network configuration. This is required for tasks hosted on Fargate and for tasks using the awsvpc network mode.
For Subnets, specify one or more subnet IDs.
For Security groups, specify one or more security group IDs.
For Auto-assign public IP, specify whether to assign a public IP address from your subnet to the task.
So the networking configuration changed between the manually run task and the scheduled task. Refer to the above to figure out the needed settings for your case.
I fixed this by enabling auto-assign public IP.
However, to do this, I had to first change from "Capacity provider strategy" -
"Use cluster default", to "Launch type" - "FARGATE". Then the option to enable auto-assign public IP became available in the dropdown in the EventBridge UI.
This seems odd to me, because my default capacity provider strategy for my cluster is Fargate. But it is working now.
Need to use a gateway to follow the traffic from ECS to ECR. It can either Internet Gateway or NAT Gateway eventually which would be effecting cost factor.
But where we can resolve this scenario, by creating VPC Endpoints. Which maintains the traffic within the AWS Resources.
Endpoints Required for this would be :
S3 Gateway
ECR
ECS

Error creating EKS cluster - send request failed caused by POST FORBIDDEN

I am provisioning an "air-gapped" EKS cluster. There is no internet access in the VPC so I have also created the following VPC endpoints: ecr.api, ecr.dkr, ec2, sts, and S3 (gateway).
I have checked that NACL allows traffic from AWS S3 CIDRs and all traffic inside the vpc. The security groups are allowing that traffic as well.
I am provisioning this with Terraform Cloud. The errors received are not very descriptive:
Error creating EKS Cluster: RequestError: send request failed caused by: POST "https://eks.eu-west-2.amazonaws.com/clusters": Forbidden
Not sure what is Forbidden in this case. Is it the access to the EKS control plane?
Update: I can deploy the EKS in the AWS console without a problem. That using the same security group, nacl and roles.
You must provide valid AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to your Terraform Cloud. These must be associated with valid permissions to perform needed operations to create the cluster.

AWS ECS Fargate Platform 1.4 error ResourceInitializationError: unable to pull secrets or registry auth: execution resource

I am using docker containers with secrets on ECS, without problems. After moving to fargate and platform 1.4 for efs support i start getting the following error.
Any help please?
ResourceInitializationError: unable to pull secrets or registry auth: execution resource retrieval failed: unable to retrieve secret from asm: service call has been retried 1 time(s): secret arn:aws:secretsmanager:eu-central-1:.....
Here's a checklist:
If your ECS tasks are in a public subnet (0.0.0.0/0 routes to Internet Gateway) make sure your tasks can call the "public" endpoint for Secrets Manager. Basically, outbound TCP/443.
If your ECS tasks are in a private subnet, make sure that one of the following is true: (a) your instances need to connect to the Internet through a NAT gateway (0.0.0.0/0 routes to NAT gateway) or (b) you have an AWS PrivateLink endpoint to secrets manager connected to your VPC (and to your subnets)
If you have an AWS PrivateLink connection, make sure the associated Security Group has inbound access from the security groups linked to your ECS tasks.
Make sure you have set GetSecretValue IAM permission to the ARN(s) of the secrets manager entry(or entries) set in the ECS "tasks role".
Edit: Here's another excellent answer - https://stackoverflow.com/a/66802973
I had the same error message, but the checklist above misses the cause of my problem. If you are using VPC endpoints to access AWS services (ie, secretsmanager, ecr, SQS, etc) then those endpoints MUST permit access to the security group that is associated with the VPC subnet that your ECS instance is running in.
Another watchit is, if you are using EFS to host volumes, ensure that your volumes can be mounted by the same security group identified above. Go to EFS, select the appropriate file system, Network tab, then Manage.