I am trying to build a sample java project and trying to build an docker image and pushing that image to AWS ECR, but facing an issue while logging into the AWS ECR.
Error: COMMAND_EXECUTION_ERROR: Error while executing command: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/z8i5y3u6. Reason: exit status 1
I used below buildspec.yml file for build. Not sure where I am doing mistake, please help me to fix this issue.
version: 0.2
phases:
install:
runtime-versions:
java: corretto8
docker: 18
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/z8i5wy3u
build:
commands:
- echo Build started on date
- mvn package
post_build:
commands:
- echo Building the Docker image...
- docker build -t atlas2-au .
- docker tag atlas2-au:latest public.ecr.aws/z8i5y3u6/atlas:latest
- docker push public.ecr.aws/z8i5y3u6/atlas2-au:latest
command and buildspec.yml is correct as per me , have you provided proper role to ECR ?
Amazon ECR requires that users have permission to make calls to the ecr:GetAuthorizationToken API through an IAM policy before they can authenticate to a registry and push or pull any images from any Amazon ECR repository. Amazon ECR provides several managed IAM policies to control user access at varying levels; for more information, see Amazon Elastic Container Registry Identity-Based Policy https://docs.aws.amazon.com/AmazonECR/latest/userguide/security_iam_id-based-policy-examples.html