How can I create an AWS ECR repository if it doesn't already exist?
To push a Docker image to an Amazon ECR repositoryAuthentication tokens must be obtained for each registry used, and the tokens are valid for 12 hours. For more information, see Private registry authentication. To authenticate Docker to an Amazon ECR registry, run the aws ecr get-login-password command.
To get started you simply enable replication, choose the destination accounts and regions you want ECR to copy images to. After this, every time you push an image to the private repository, ECR automatically replicates the image.
One liner to create a repo if it doesn't exist (or the describe command fails for any other reason):
aws ecr describe-repositories --repository-names ${REPO_NAME} || aws ecr create-repository --repository-name ${REPO_NAME}
AWS makes the repository only if it doesn't exist. You can simply ignore the error & failure with|| true
in case if same repository exists:
aws ecr create-repository --repository-name <repo_name> || true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With