In this article, we will see how a user can reset the bookmark of a job present in ann AWS account.
Example
Reset the bookmark of a job available in an AWS Glue Data Catalog.
Problem Statement: Use boto3 library in Python to reset the bookmark of a job.
Approach/Algorithm to solve this problem
Step 1: Import boto3 and botocore exceptions to handle exceptions.
Step 2: job_name is the parameter 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 reset_job_bookmark function and pass the parameter job_name as JobName.
Step 6: It returns a dictionary having the details of Job bookmark entry.
Step 7: Handle the generic exception if something went wrong while resetting the bookmark.
Example Code
The following code resets the bookmark of a job −
import boto3 from botocore.exceptions import ClientError def reset_bookmark_of_a_job(job_name) session = boto3.session.Session() glue_client = session.client('glue') try: response = glue_client.reset_job_bookmark(JobName=job_name) return response except ClientError as e: raise Exception("boto3 client error in reset_bookmark_of_a_job: " + e.__str__()) except Exception as e: raise Exception("Unexpected error in reset_bookmark_of_a_job: " + e.__str__()) print(reset_bookmark_of_a_job("test_job"))
Output
{'JobBookmarkEntry': {'JobName': 'test-job', 'Version': 3, 'Run': 3, 'Attempt': 0, 'JobBookmark': ''}, 'ResponseMetadata': {'RequestId': '03d40d90-******************f', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 27 Mar 2021 10:14:58 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '104', 'connection': 'keep-alive', 'x-amzn-requestid': '03d40d90-***************************f'}, 'RetryAttempts': 0}}