Search code examples
amazon-web-servicesdockeramazon-ecsamazon-ecr

I cant push Docker image to AWS ecr


I'm trying to push a Docker image from Dockerfile built to AWS ECR but when run this command:

$ aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 477629773586.dkr.ecr.eu-west-1.amazonaws.com 

appears the error:

An error occurred (AccessDeniedException) when calling the GetAuthorizationToken operation: User: arn:aws:iam::477629773586:user/albertosanmartin is not authorized to perform: ecr:GetAuthorizationToken on resource: * Error: Cannot perform an interactive login from a non TTY device

I have installed and configured those files:

~/.aws/configure:

[default]
...
[mrthink]
region = eu-west-1
output = json

~/.aws/credentials

[default]
...
[mrthink]
aws_access_key_id = ****
aws_secret_access_key = ****

Seems to the command api get other user "albertosanmartin"

Anybody could help me please ? Thanks in advance.


Solution

  • If you have your credentials configured under mrthink profile name in ~/.aws/credentials you need to pass the --profile param to the aws cli

    $ aws  --profile mrthink ecr get-login-password \
    --region eu-west-1 |\
    docker login --username AWS \
    --password-stdin 477629773586.dkr.ecr.eu-west-1.amazonaws.com 
    

    The user arn:aws:iam::477629773586:user/albertosanmartin doesnt have access to ECR

    You can double-check your credentials via sts get-caller-identity call if they are which you want to use.