How to push an image to public ECR repository
Asked by siddharthjoshi:

I have tried using "atlassian/aws-ecr-push-image:1.4.2" to push an image to an existing repository in my AWS account. But unfortunately the pipe is only being able push to private repositories.

When i create a repository in public registry and try the same getting this following error

"The repository with name 'xxxxxxxx' does not exist in the registry with id 'xxxxxxxxx'"


Answers:
author: Igor Stoyanov
body: [@siddharthjoshi](/t5/user/viewprofilepage/user-id/4557434), [@Kushan Harshana Gunasekera](/t5/user/viewprofilepage/user-id/4567214) hi. We released new version of pipe:

```
  - pipe: atlassian/aws-ecr-push-image:1.5.0    variables:      AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID      AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY      IMAGE_NAME: my-docker-image      ECR_PUBLIC: "true"      PUBLIC_REGISTRY_ALIAS: registry-alias
```

with support of pushing images to ECR Public Registry.

Please, provide us feedback.

Regards, Igor.

comments: author: siddharthjoshi
body: I would love to try this out [@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492) , Will update one of my repositories and come back to you !!!

Thanks,

<br />

Siddharth Joshi K


author: Kushan Harshana Gunasekera
body: Glad to hear that [@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492) , I'll try it out. You have been a great help, Thank you [@Igor Stoyanov](/t5/user/viewprofilepage/user-id/4550492) .


author: Kushan Harshana Gunasekera
body: Here I've mentioned the reasons why this is happen in the Stack Overflow. Please have a look.

<https://stackoverflow.com/q/69274998/6194097>

I think the "atlassian/aws-ecr-push-image:1.4.2" image doesn't support [Amazon ECR Public repositories](https://docs.aws.amazon.com/AmazonECR/latest/public/what-is-ecr.html). I had the same issue, what I did was [manually installed the AWS CLI version 2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install) in the pipeline and ran all the push commands.

That's it, but you must provide the region as **us-east-1**. Otherwise you'll get the same error again and again.

comments: author: siddharthjoshi
body: Yes, funnily i actually did the same :D

And even i faced this weird region (us-east-1) restrictions. But as you mentioned "atlassian/aws-ecr-push-image:1.4.2" does not seem to support public repo, as by default it's looking for a repo in the mentioned name in the private ECR and there were no parameters we could use to make it look in the public repo.


author: Oleksandr Kyrdan
body: Hi [@siddharthjoshi](/t5/user/viewprofilepage/user-id/4557434)

Thank you for your question!

Have you provided all parameters required parameters for pipe?  
Do you have permissions to push images to that repository?  
It would be nice if you provide us with more details to help you: pipeline configuration, logs, etc.

Cheers,  
Oleksandr Kyrdan

comments: author: Kushan Harshana Gunasekera
body: Hello [@Oleksandr Kyrdan](/t5/user/viewprofilepage/user-id/2885705)

I'm having the same issue, the thing is Amazon ECR now supports public repositories. The **aws ecr** command is using for the private repositories and **aws ecr-public** command is using for the public repositories and public repositories are only work with **us-east-1** region. I've addressed this issue in the Stack Overflow, please have a look for more details.

<https://stackoverflow.com/q/69274998/6194097>


author: siddharthjoshi
body: [@Oleksandr Kyrdan](/t5/user/viewprofilepage/user-id/2885705) What [@Kushan Harshana Gunasekera](/t5/user/viewprofilepage/user-id/4567214) mentions is correct, to push to the public repo we need to use "aws ecr-public". I have permission to push to the repo, i have already pushed few images to my private repo and also i was able to push to public repo by writing the commands manually. The code below show how i managed to push the code to public ECR

*** ** * ** ***

\`\`\`  
pipelines:  
default:  
- step:  
name: "Build server image"  
services:  
- docker  
script:  
- apt-get update  
- docker build -t \<image-name\> .  
- apt-get install -y python3-pip  
- pip3 install -U awscli  
- aws configure set aws_access_key_id \<access-key-id\>  
- aws configure set aws_secret_access_key \<secret-key\>  
- aws ecr-public get-login-password --region us-east-1 \| docker login --username AWS --password-stdin public.ecr.aws  
- docker tag \<image-name\> public.ecr.aws/\<repo-name\>/\<image-name\>  
- docker push public.ecr.aws/\<repo-name\>/\<image-name\>

\`\`\`


Tags: aws

bitbucket-pipelines