By using AWS re:Post, you agree to the Terms of Use

Docker push doesn't work even docker login succeeded during AWS CodePipeline Build stage



I'm preparing CI/CD using AWS CodePipeline. Unfortunatelly I have an error during build stage. Below there is content of my buildspec.yml file, where:

AWS_DEFAULT_REGION = eu-central-1



version: 0.2
      java: corretto11
      - echo Logging in to Amazon ECR...
      - aws --version
      - TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
      - echo Build started on `date`
      - echo $IMAGE_URI
      - mvn clean package -Ddockerfile.skip
      - docker build --tag $IMAGE_URI .
      - printenv
      - echo Build completed on `date`
      - echo $(docker images)
      - echo Pushing docker image
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin <ACCOUNT_ID>
      - docker push $IMAGE_URI
      - echo push completed
      - printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $IMAGE_URI > imagedefinitions.json
    - imagedefinitions.json

I got error:

[Container] 2022/01/06 19:57:36 Running command aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin <ACCOUNT_ID>
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See

Login Succeeded
[Container] 2022/01/06 19:57:37 Running command docker push $IMAGE_URI
The push refers to repository [<ACCOUNT_ID>]
37256fb2fd27: Preparing
fe6c1ddaab26: Preparing
d4dfab969171: Preparing
no basic auth credentials

[Container] 2022/01/06 19:57:37 Command did not exit successfully docker push $IMAGE_URI exit status 1
[Container] 2022/01/06 19:57:37 Phase complete: POST_BUILD State: FAILED
[Container] 2022/01/06 19:57:37 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker push $IMAGE_URI. Reason: exit status 1

Even docker logged in successfully there is "no basic auth credentials" error. Do you know what could be a problem?

Best regards.

2 Answers
Accepted Answer

Is it possible you have authenticated to eu-central-1 and then you try to push to us-east-1?

Authentication requests are tied to specific regions, and cannot be used across regions. For example, if you obtain an authorization token from eu-central-1, you cannot use it to authenticate against your repositories in us-east-1.

answered 9 months ago
  • You're totally right. Silly mistake. I wrote that REPOSITORY_URI is


    while in my environments it was:


    I forgot to update this value. Thanks for your tip. Best regards


Everything in the flow looks fine thb.

Maybe there is something wrong with $IMAGE_URI? ECR Repo name or AWS Region?

Is cicd-1-app the ECR repo name?

profile picture
answered 9 months ago
  • Problem solved. My silly mistake with bad region name for REPOSITORY_URI. Check my answer above. Thanks for your message. Best regards.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions