Search code examples
pythonamazon-web-servicesboto3amazon-ecr

Trying to limit or filter the output of client.describe_repositories()


I have a simple lambda function to print out my repositories. I would like to print out only the repositoryName instead of everything. Is there a simple way to filter out everything else?

import json
import boto3

def lambda_handler(event, context):
    
    client = boto3.client('ecr')
    reponames = client.describe_repositories()
    
    print(reponames)
    
    return {
        'body': json.dumps("hello world")
    }

Solution

  • The above comment from jordanm worked to solve the problem. Replacing my "reponames" statement with his worked. I'll post it here for clarity.

    # reponames = client.describe_repositories()
    reponames = [repo['repositoryName'] for repo in client.describe_repositories()['repositories']]