Interview Prep/AWS/ECS, EKS, ECR and Lambda

`docker push 111111111111.dkr.ecr.us-east-1.amazonaws.com/api:1.4` fails with `no basic auth credentials` (or `denied: Your authorization token has expired. Reauthenticate and try again.`).

BeginnerTroubleshootingECS, EKS, ECR and Lambda
Answer

Likely causes → Docker never logged in to that registry and Region, or the ECR token (valid for 12 hours) expired. Another cause: the repository does not exist (name unknown: The repository with name 'api' does not exist in the registry).

Diagnose →

aws sts get-caller-identity
aws ecr describe-repositories --repository-names api --region us-east-1
cat ~/.docker/config.json | grep -A2 dkr.ecr

Fix →

aws ecr get-login-password --region us-east-1 | \
  docker login --username AWS --password-stdin 111111111111.dkr.ecr.us-east-1.amazonaws.com
aws ecr create-repository --repository-name api --image-scanning-configuration scanOnPush=true

Prevent → In CI, log in at the start of every job (for example, aws-actions/amazon-ecr-login), or use amazon-ecr-credential-helper.

aws All AWS questions Roadmap: EKS, ECS & serverless on AWS

More on ECS, EKS, ECR and Lambda