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') | |
| ) | |
| ) |