How to get the details of a workflow using Boto3

AWSBoto3PythonServer Side ProgrammingProgramming

In this article, we will see how a user can get the resource metadata of a workflow.


Get the details of a workflow from AWS Glue Data Catalog that is created in your account.

Problem Statement: Use boto3 library in Python to get the metadata of a workflow that is created in your account.

Approach/Algorithm to solve this problem

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

  • Step 2: workflow_name is the required parameter for this function. It will fetch the metadata of the given workflow.

  • 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: Call get_workflow and pass the workflow_name as Name parameter.

  • Step 6: It returns the metadata of a given workflow.

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

Example Code

The following code fetches the details of a workflow created in user account −

import boto3
from botocore.exceptions import ClientError

def get_resource_maetadata_of_workflow(workflow_name):
   session = boto3.session.Session()
   glue_client = session.client('glue')
      response = glue_client.get_workflow(Name=workflow_name)
return response
   except ClientError as e:
      raise Exception("boto3 client error in get_resource_maetadata_of_workflow: " + e.__str__())
   except Exception as e:
      raise Exception("Unexpected error in get_resource_maetadata_of_workflow: " + e.__str__())
a = get_resource_maetadata_of_workflow('dev-aiml-naviga-ods-load')


{'Workflow': {'Name': 'dev-aiml-naviga-ods-load', 'DefaultRunProperties': {}, 'CreatedOn': datetime.datetime(2020, 5, 27, 3, 10, 57, 967000, tzinfo=tzlocal()), 'LastModifiedOn': datetime.datetime(2020, 5, 27, 3, 10, 57, 967000, tzinfo=tzlocal())}, 'StartedOn': datetime.datetime(2021, 2, 3, 16, 14, 48, 795000, tzinfo=tzlocal()), 'CompletedOn': datetime.datetime(2021, 2, 3, 16, 28, 6, 207000, tzinfo=tzlocal()), 'Status': 'COMPLETED', 'Statistics': {'TotalActions': 3, 'TimeoutActions': 0, 'FailedActions': 0, 'StoppedActions': 0, 'SucceededActions': 3, 'RunningActions': 0}}}, 'MissingWorkflows': [], 'ResponseMetadata': {'RequestId': 'b328d064-24ab-48c4-b058-852387a3d474', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 27 Feb 2021 13:57:37 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '2655', 'connection': 'keep-alive', 'x-amzn-requestid': 'b328d064-24ab-48c4-b058-852387a3d474'}, 'RetryAttempts': 0}}
Updated on 15-Apr-2021 12:49:03