How to use Boto3 to get the list of workflows present an in AWS account


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

Example

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

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

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 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_workflows function

  • Step 6: It returns the list of all workflows present in the AWS Glue data catalog. If there are no workflows, it returns an empty dict.

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

Example Code

The following code fetches the list of all workflows −

import boto3
from botocore.exceptions import ClientError

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

Output

{'Workflows':
['tick-data-etl', 'test-wf-daily-jobs'],
'ResponseMetadata': {'RequestId': '3824e47a-***************e6d', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 27 Mar 2021 09:47:38 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '64', 'connection': 'keep-alive', 'x-amzn-requestid': '3824e47a-********************e6d'}, 'RetryAttempts': 0}}

Updated on: 15-Apr-2021

167 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements