Skip to content

Instantly share code, notes, and snippets.

@danielpsf
Last active March 22, 2022 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpsf/43b3b6945773274b2ec11d1ab930ce99 to your computer and use it in GitHub Desktop.
Save danielpsf/43b3b6945773274b2ec11d1ab930ce99 to your computer and use it in GitHub Desktop.
List (with some limitations) all ECR images

Usage:

  • Install boto3 pip install boto3
  • Execute the script: python list_ecr_images.py --profile your_profile_goes_here --region your_region_goes_here
from ast import parse
import boto3
import argparse
parser = argparse.ArgumentParser(
usage="list_ecr_images.py --profile YOUR_PROFILE --region YOUR_REGION",
description="Print all image details for reporting purpose"
)
parser.add_argument('--profile', required=True)
parser.add_argument('--region', required=True)
args = parser.parse_args()
session = boto3.Session(profile_name=args.profile)
client = session.client('ecr', region_name=args.region, )
repos = client.describe_repositories(maxResults=1000)
for repo in repos['repositories']:
images = client.describe_images(
registryId=repo['registryId'],
repositoryName=repo['repositoryName'],
maxResults=1000
)
for image in images['imageDetails']:
print('{repo}; {pushedAt}; {sha}; {size}; {tags}'.format(repo=repo['repositoryName'],
pushedAt=image['imagePushedAt'],
sha=image['imageDigest'],
size=image['imageSizeInBytes'],
tags=image.get('imageTags')
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment