How to get the list of all registries present in an AWS account using Boto3


In this article, we will see how a user can get the list of all registries present in an AWS account.

Example

Get the list of all registries available in AWS Glue Data Catalog.

Problem Statement: Use boto3 library in Python to get the list of all registries.

Approach/Algorithm to solve this problem

  • Step 1: Import boto3 and botocore exceptions to handle exceptions.

  • Step 2: There are no parameters in this function.

  • Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.

  • Step 4: Create an AWS client for glue.

  • Step 5: Now use the list_registries

  • Step 6: It returns the list of all registries present in AWS Glue data catalog with limited details of registry. It doesn't include the registries whose status is Deleting. It only has the list of available registries. If there are no registries, then it returns an empty dict.

  • Step 7: Handle the generic exception if something went wrong while checking the job.

Example Code

The following code fetches the list of all registries −

import boto3
from botocore.exceptions import ClientError

def list_of_registries()
   session = boto3.session.Session()
   glue_client = session.client('glue')
   try:
      registries_name = glue_client.list_registries()
      return registries_name
   except ClientError as e:
      raise Exception("boto3 client error in list_of_registries: " + e.__str__())
   except Exception as e:
      raise Exception("Unexpected error in list_of_registries: " + e.__str__())
print(list_of_registries())

Output

{
   'Registries':[
   {
      'RegistryName': 'employee_details',
      'RegistryArn': 'string',
      'Description': 'Registry for employees record',
      'Status': 'AVAILABLE',
      'CreatedTime': 'string',
      'UpdatedTime': 'string'
   },
   {
      'RegistryName': 'security_details',
      'RegistryArn': 'string',
      'Description': 'Registry for security record',
      'Status': 'AVAILABLE',
      'CreatedTime': 'string',
      'UpdatedTime': 'string'
   },
],
'Request': ……
}

Updated on: 15-Apr-2021

75 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements