Skip to content

Instantly share code, notes, and snippets.

@nathanieltalbot
Created November 4, 2019 19:34
Show Gist options
  • Save nathanieltalbot/784d49d2418c0fb8b656f1959d0f4624 to your computer and use it in GitHub Desktop.
Save nathanieltalbot/784d49d2418c0fb8b656f1959d0f4624 to your computer and use it in GitHub Desktop.
A simple Python function to check if an image tag exists in an ECR repo using boto3
# Checks if an image tag exists in the repo
def check_tag_exists(tag, repo):
ecr_client = boto3.client('ecr', region_name='us-east-1')
response = ecr_client.describe_images(repositoryName=repo, filter={'tagStatus': 'TAGGED'})
for i in response['imageDetails']:
if tag in i['imageTags']:
return True
return False
@PelegAtVia
Copy link

This does not handle pagination, if there are more than 100 images in your repo this might fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment