docker-archive / for-aws

92 stars 26 forks source link

AWS ECR Login Failure #187

Closed kedarparallel closed 5 years ago

kedarparallel commented 5 years ago

Expected behavior

  1. eval $(aws ecr get-login --no-include-email --region ${aws_ecr_region})
  2. TOKEN=$(aws ecr get-authorization-token --output text --query 'authorizationData[].authorizationToken') docker login -u AWS -p ${TOKEN} http://${aws_container_registry_name}
  3. echo "$(aws ecr get-authorization-token --region ${aws_ecr_region} --output text --query 'authorizationData[].authorizationToken' | base64 -d | cut -d: -f2) | docker login -u AWS https://${aws_container_registry_name} --password-stdin"

Actual behavior

All 3 of the options mentioned above give error:

Error response from daemon: login attempt to https://XXXXXX.dkr.ecr.us-west-2.amazonaws.com/v2/ failed with status: 400 Bad Request

However, if I simply copy paste these commands(after substituting variables) and manually execute, all of them work fine.

Information

Steps to reproduce the behavior

  1. eval $(aws ecr get-login --no-include-email --region ${aws_ecr_region}) from within script or 1 or 2 mentioned in 'Expected Behaviour'
kedarparallel commented 5 years ago

Running bash script in debug mode helped me solve issue. If you just run eval $(aws ecr get-login --no-include-email --region ${aws_ecr_region}) for some reason between password and ecr name it adds 3 spaces while you actually need ==

So I replaced it with following code:

cmd=$(aws ecr get-login --no-include-email --region ${aws_ecr_region})
spaces="   "
equals="=="
eval "${cmd/$spaces/$equals}"