Getting error on aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin

Viewed 1539

In the beginning, this command worked. But, now it is not working.

aws configure
aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.us-east-2.amazonaws.com

output is:

An error occurred (UnrecognizedClientException) when calling the GetAuthorizationToken operation: The security token included in the request is invalid
Error: Cannot perform an interactive login from a non TTY device

aws cli version is:

aws --version
aws-cli/2.2.41 Python/3.8.8 Linux/4.15.0-101-generic exe/x86_64.linuxmint.19 prompt/off

When I use different computer with same access-key and secret-key, following command works:

aws configure
aws ecr get-login-password --region us-east-2 | docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.us-east-2.amazonaws.com

output was:

WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

So, I think access-key and secret-key are fine. And, there is something wrong with aws-cli configuration. I have also tried reinstalling aws-cli but no success. Source I used to reinstall aws-cli: reinstall aws-cli

OS in which it's not working: Linux Mint 19 OS in which it worked: Ubuntu 20.04

1 Answers

I was running aws ecr command in root user which was not giving proper error message.

When I run aws ecr command in public user, then it gave a proper error message, i.e., Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock; So, I changed the permission of this file docker.sock from user root to public user and group docker to docker using command: chown myPublicUser:docker /var/run/docker.sock

Now, run aws ecr using public user, it should work.

Related