Approach/Algorithm to solve this problem
Step 1 − Import boto3 and botocore exceptions to handle exceptions.
Step 2 − No parameter is required for this function. It will fetch all listed triggers for user account and then display metadata of each triggers.
Step 3 − Create an AWS session using boto3 library. 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 list_workflows function to get all jobs those are listed in user account.
Step 6 − Call batch_get_workflows and pass the job names fetched in previous function.
Step 7 − It returns list_of_workflows and metadata of each workflows.
Step 8 − Handle the generic exception if something went wrong while checking the job.
Example
Use the following code to fetch the details of each workflow created in the user account −
import boto3 from botocore.exceptions import ClientError def get_resource_maetadata_of_workflows(): session = boto3.session.Session() glue_client = session.client('glue') try: list_of_workflows = glue_client.list_workflows() response = glue_client.batch_get_workflows( Names=list_of_workflows['Workflows']) return list_of_workflows, response except ClientError as e: raise Exception( "boto3 client error in get_resource_maetadata_of_workflows: " + e.__str__()) except Exception as e: raise Exception( "Unexpected error in get_resource_maetadata_of_workflows: " + e.__str__()) a, b = get_resource_maetadata_of_workflows() #List of Workflows print(a) #Resource metadata of each Workflow print(b)
Output
#List of Workflows {'Workflows': ['dev-aiml-naviga-ods-load'], 'ResponseMetadata': {'RequestId': '556890ce-bcd1-4bb0-9c33-3ae1db13f3a9', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 27 Feb 2021 13:57:37 GMT', 'contenttype': 'application/x-amz-json-1.1', 'content-length': '91', 'connection': 'keep-alive', 'x-amzn-requestid': '556890ce-bcd1-4bb0- 9c33-3ae1db13f3a9'}, 'RetryAttempts': 0}} #Resource metadata of each Workflow {'Workflows': [{'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}}