Closed flah00 closed 4 years ago
Hi @flah00,
Sorry to hear you're having trouble with this! I tried to reproduce, but without success. I successfully logged into my ECR through docker in both us-east-1
and us-west-2
. I could only reproduce if I forced a region mismatch between the get-login-password
and the URL:
> aws --version
aws-cli/2.0.21 Python/3.7.4 Darwin/19.5.0 botocore/2.0.0dev25
> aws ecr get-login-password --region us-east-1 \
| docker -l "debug" login \
-u AWS \
--password-stdin XXXXXXX.dkr.ecr.us-west-2.amazonaws.com
Error response from daemon: login attempt to https://XXXXXXXXXXX.dkr.ecr.us-west-1.amazonaws.com/v2/ failed with status: 400 Bad Request
The command referenced in the aws-iam-authenticator
image release notes is for the v1 of the CLI client and wouldn't work for you using v2. I'll make a note to follow up on that, thanks for catching it!
Can you double check that your environment variables in use here are set to the same region? I could only think otherwise that the profile you referenced in the get-login-password
is for a different AWS account than specified in the docker login
.
Thanks!
@kdaily I re-ran the commands, as I had laid out and they're working now... no changes on my end. Very curious. Thanks for digging into this.
I seem to be having exactly the same problem atm with
aws ecr get-login --region "${AWS_DEFAULT_REGION}" | docker login --username AWS --password-stdin "${AWS_ACCESS_KEY_ID}.dkr.ecr.eu-west-1.amazonaws.com"
Error response from daemon: login attempt to https://XXXXXXXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/v2/ failed with status: 400 Bad Request
My version-set is this:
$ aws --version
aws-cli/1.16.209 Python/3.7.7 Darwin/19.5.0 botocore/1.12.199
$ uname -a
Darwin terminaator 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
@Fornacula what's the value of AWS_DEFAULT_REGION
?
Facing the same issue with AWS ECR plugin in JENKINS using
aws ecr get-login --region us-east-1 --no-include-email
Error response in JENKINS console:
Error response from daemon: login attempt to https://{AWS_ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/v2/ failed with status: 400 Bad Request
$ aws --version
aws-cli/1.11.131 Python/2.7.16 Linux/4.9.91-40.57.amzn1.x86_64 botocore/1.5.94
$ name -a
Linux ip-172-31-71-174 4.9.91-40.57.amzn1.x86_64 #1 SMP Tue Apr 3 17:32:06 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
UPDATE 1 Tried manually from CLI and it worked but not working from the PLUGIN, could be a plugin issue.
UPDATE 2 There is no issue, it was typo in ecr credential ID used by plugin and it worked. Please ignore my comment.
Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.
This still happens... any solution? I think I am losing my mind, at least 3 hours trying to make this work
I'm still getting the 400 Bad Request error. I've tried changing regions and all of the suggestions made above but nothing is working.
I'm in Cape Town, South Africa and I've tried both the Cape Town and us-east-1 regions but both don't work. I'm not sure what else could be the problem.
I'm executing the command in the suggested format: aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
I have aws-cli/2.1.32 Python/3.8.8 Darwin/19.6.0 exe/x86_64
and Docker 3.2.2 running on Mac OS Catalina 10.15.17
Are there any updates regarding this problem? Please some one help me I'm going insane over here
I ran into this issue and was able to resolve it by:
aws --region us-east-1 ecr get-login-password
aws sts get-caller-identity
to verify your account ID (make sure you are looking at Account
and not UserId
Just in case it helps someone - if your AWS account number starts with a zero, your automation might round this number away and therefore interpolates the incorrect account ID into the login command. Just to be clear, the login command to the repo absolutely requires the zero to be present.
- aws sts get-caller-identity
Yes this helps me, I am passing account alias instead of id. Thanks
For those you who are facing this issue in powershell, here is the workaround: https://stackoverflow.com/questions/65576285/docker-login-on-ecr-fails-with-400-bad-request-on-powershell-from-jenkins
I seem to be having exactly the same problem atm with
aws ecr get-login --region "${AWS_DEFAULT_REGION}" | docker login --username AWS --password-stdin
The problem here is that you're calling get-login
instead of get-login-password
: the result of get-login
does not need to be piped into docker
, because it's already the full command you have to run! I know because it got me for a while too...
If you can switch to get-login-password
then just do that (since get-login
is deprecated). Otherwise, my solution was:
eval "$(aws ecr get-login --region "${AWS_DEFAULT_REGION}")"
I seem to be having exactly the same problem atm with
aws ecr get-login --region "${AWS_DEFAULT_REGION}" | docker login --username AWS --password-stdin
The problem here is that you're calling
get-login
instead ofget-login-password
: the result ofget-login
does not need to be piped intodocker
, because it's already the full command you have to run! I know because it got me for a while too...
This comment just saved me :)
For myself, I fixed the problem because I was using dashes in the AWS Account ID. Amazon lists the ID with dashes, but you have to remove the dashes for this to work.
I resolved this by ensuring my region was consistent between the ecr repo location and the login password:
aws ecr get-login-password --region SAME-REGION-1 | docker login --username AWS --password-stdin 12345678.dkr.ecr.SAME-REGION-1.amazonaws.com/repo/name
Have the same problem with login from powershell, but works from CMD
this solution is working fine for me.
solution:- https://stackoverflow.com/a/69274999/6194097
For me the cause of the problem was using the fish shell. I ran the same command in a bash shell and it succeeded.
I am having this issue in us-west-1, running on macOS, zsh shell. macOS: 12.6.1 (21G217) -- Intel zsh: 5.8.1 aws cli: 2.9.1 -- note, auth via SSO docker: 20.10.21
I have confirmed region, environment variables, my permissions all align with the required parameters.
I have confirmed that others in my company having the same permissions and similar configurations do not have the issue, so seems likely to be due to some configuration.
Failed: I was able to reproduce the problem with zsh
shell
Worked: I was able to successfully run with bash
shell (in my case gnu bash 5.1 installed via brew install bash
)
And then in an attempt to diagnose the problem, I added --debug
to the docker command, and that also made it work...
[~]$ aws ecr get-login-password --region us-west-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-1.amazonaws.com
Error response from daemon: login attempt to https://123456789012.dkr.ecr.us-west-1.amazonaws.com/v2/ failed with status: 400 Bad Request
[~]$ aws ecr get-login-password --region us-west-1 | docker --debug login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-1.amazonaws.com
Login Succeeded
[~]$ aws ecr get-login-password --region us-west-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-1.amazonaws.com tfenv:1.3.0
Error response from daemon: login attempt to https://123456789012.dkr.ecr.us-west-1.amazonaws.com/v2/ failed with status: 400 Bad Request
Hope this helps others!
In case anyone else runs into this issue, I had to wrap my GetAuthToken call in a variable definition for it to be piped in succesfully:
echo $(aws ecr get-login-password --region $AWS_REGION) | docker login -u AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
I couldn't find any reference to this anywhere, and thank god GPT4 suggested I do it. /shrug
aws ecr get-login-password --profile $PROFILE --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
Login Succeeded
For me, I found out that it is due to aws cli
auto prompt, it breaks the piping of password to docker stdin, after switching to AWS_CLI_AUTO_PROMPT=on-partial
it works
For anyone still struggling with this, in my case the issue was my AWS Account ID had a leading zero and was being parsed as a number by GitHub Actions when passed to the env
argument, truncating the zero. Ie, "01234"
was being treated 1234
.
I don't know why AWS account Ids are numbers but really strings with leading zeros. Nice. GitHub, for its part, is doing magic on those env
variables which I would assume would be strings, like if it was done in the shell with export
. The confluence of these two idiosyncrasies caused me to lose over 8 hours diagnosing this issue. Fun. Hopefully, this will help someone else. 😵💫
If anyone is using authorization token and struggling i have put the answer here:
I have occured same error. I create aws ecr repo in ap-northeast-2, but login token created base on us-east-1 .
after 13 hours, the solution for me was using the command line directly and then apply this: https://stackoverflow.com/questions/60583847/aws-ecr-saying-cannot-perform-an-interactive-login-from-a-non-tty-device-after
hope it helps somebody
I had to restart my powershell and then this worked. Used the exact same commands (copied/pasted) Weird...
OK, for those who are still hitting this, mine was especially dumb. This works:
aws --profile ... --region us-west-2 ecr get-login-password | docker login --password-stdin --username AWS XXXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com
But this does not:
aws --profile ... --region us-west-2 ecr get-login-password | docker login --password-stdin --username AWS XXXX-XXXX-XXXX.dkr.ecr.us-west-2.amazonaws.com
Kill the dashes -- thanks to this: https://github.com/aws/aws-cli/issues/5317#issuecomment-1113571931, rewriting as my guess is more people will see this...
If the AWS folks want to add support for dashes, I don't think anyone would complain :)
Confirm by changing [ ] to [x] below to ensure that it's a bug:
Describe the bug I want to login into ECR in us-west-2, because I would like to pull the aws-iam-authenticator image, ie
docker pull 602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-iam-authenticator:v0.5.0-alpine-3.7
. The docker login instructions on the release page are out of date. I followed the instructions in the AWS CLI get-login-password, but I get HTTP error code 400 back from the server.SDK version number
Platform/OS/Hardware/Device What are you running the cli on?
To Reproduce (observed behavior)
Expected behavior I should be logged in, but I am not
Logs/output
Additional context I have found that I can successfully docker login to region us-east-1, but I cannot login to us-west-2. I need to login to us-west-2, so I can pull
602401143452.dkr.ecr.us-west-2.amazonaws.com/amazon/aws-iam-authenticator:v0.5.0-alpine-3.7
. I looked over the status of ECR for us-west-2 and it's not reporting any issues.