How to use Boto3 to update the details of a workflow in AWS Glue Catalog


In this article, we will see how to update the details of a workflow in AWS Glue Catalog.

Example

Problem Statement: Use boto3 library in Python to update details 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. Description and deault_run_properties are optional parameter. It updates the details of a 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 update_workflow and pass the workflow_name as Name parameter and description as Description and default_run_properties as DefaultRunProperties.

  • 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 updates the details of a workflow created in user account −

import boto3
from botocore.exceptions import ClientError

def update_resource_detail_of_workflow(workflow_name, description=None,       default_run_properties=None:dict):
   session = boto3.session.Session()
   glue_client = session.client('glue')
   try:
      response = glue_client.update_workflow(Name=workflow_name, Description = description, DefaultRunProperties = default_run_properties)                              
return response
   except ClientError as e:
      raise Exception("boto3 client error in update_resource_detail_of_workflow: " + e.__str__())
   except Exception as e:
      raise Exception("Unexpected error in update_resource_detail_of_workflow: " + e.__str__())
a = update_resource_detail_of_workflow('dev-aiml-naviga-ods-load', 'test')
print(a)

Output

{'Name': 'dev-aiml-naviga-ods-load', '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

224 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements