Amazon ECR – Adding a tag to an image after it’s already pushed

The steps are taken from http://docs.aws.amazon.com/AmazonECR/latest/userguide/retag-aws-cli.html. The issue I ran into is the wrong regions are selected. This is fixed with the –region param.

This is useful for adding tags to your :latest image. For example, QA looks at :latest, but my prod service looks for image :prod. I’ll also add a tag for the prod deployment date.


MY_MANIFEST=$(aws ecr batch-get-image --repository-name REPO_NAME --image-ids imageTag=latest --region us-west-2 --query images[].imageManifest --output text)

aws ecr put-image --repository-name REPO_NAME --image-tag NEW_TAG_NAME --image-manifest "$MY_MANIFEST" --region us-west-2
Share this:

3 comments, add yours.

Todd

Thank you for this! It was exactly what I needed to overcome today’s hurdle.

Michael Harris

This doesn’t seem to work anymore, unfortunately. Rather than retagging an existing image, it appears instead to copy the existing image and add the new tag to the new image.

INSTEAD OF:
ImageOne with digest “foo” and existing tag “v0.1” –> ImageOne with digest “foo” with two tags [“v0.1”, “dev”]

WE GET:
ImageOne with digest “foo” and existing tag “v0.1” –> ImageOne with digest “foo” and original tag “v0.1” AND ImageTwo with digest “bar” and new tag “dev”

Leave a comment