ECR can create automaticaly when image pushed
Source: Dev.to
Overview
Amazon Elastic Container Registry (ECR) can automatically create a repository when you push an image that targets a non‑existent repository. This feature simplifies workflows by eliminating the need to pre‑create repositories.
Prerequisites
- An AWS account with permissions to push images to ECR.
- The AWS CLI installed and configured.
- Docker (or Docker Buildx) installed.
Steps
1. (Optional) Create a repository‑creation template
If you want to enforce a naming prefix or set default repository settings (e.g., image tag mutability), create a Repository Create template in the ECR console or via the AWS CLI. The template can also specify whether image tags are mutable or immutable.
2. Build the Docker image
docker buildx build -t test-auto-create --platform=linux/amd64 .
3. Authenticate Docker to ECR
aws ecr get-login-password --region us-west-2 |
docker login --username AWS --password-stdin xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com
4. Tag the image for the target repository
docker tag 3413614e55cd xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/test-auto-create:latest
5. Push the image
docker push xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/test-auto-create:latest
When the push completes, ECR automatically creates the test-auto-create repository.
Verification
Run the following command before and after the push to see the repository appear:
aws ecr describe-repositories --registry-id xxxxxxxxxxxx
Sample output after the push:
{
"repositoryArn": "arn:aws:ecr:us-west-2:xxxxxxxxxxxx:repository/test-auto-create",
"registryId": "xxxxxxxxxxxx",
"repositoryName": "test-auto-create",
"repositoryUri": "xxxxxxxxxxxx.dkr.ecr.us-west-2.amazonaws.com/test-auto-create",
"createdAt": "2025-12-21T12:39:57.362000+09:00",
"imageTagMutability": "IMMUTABLE",
"imageScanningConfiguration": {
"scanOnPush": false
},
"encryptionConfiguration": {
"encryptionType": "AES256"
}
}
Additional Notes
- The automatic creation also works for pull‑through cache repositories, making it easier to cache images from ECR Public or Docker Hub.
- Repository settings (e.g., tag mutability, scan on push, encryption) can be controlled globally via the repository‑creation template. If no template is defined, default settings are applied.