- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use Boto3 to delete a glue job from AWS Glue?
Problem Statement − Use boto3 library in Python to delete a glue job, created in your account.
Example − Delete a glue job ‘transfer_from_s3’ that is created in your account.
Approach/Algorithm to solve this problem
Step 1 − Import boto3 and botocore exceptions to handle exceptions.
Step 2 − Pass the parameter job_name that should be deleted from AWS Glue Catalog.
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 delete_job function and pass the job_name as JobName parameter.
Step 6 − It will delete the job and return the response metadata.
Step 7 − Handle the generic exception if something went wrong while checking the job.
Note − After the completion of this operation, it deletes a specified job definition. If job is not found in AWS Glue, it doesn’t throw any exception and output is similar if it deletes any.
Example
Use the following code to delete a glue job from AWS Glue:
import boto3 from botocore.exceptions import ClientError def delete_a_glue_job(job_name): session = boto3.session.Session() glue_client = session.client('glue') try: response = glue_client.delelte_job(JobName=job_name) return response except ClientError as e: raise Exception( "boto3 client error in delete_a_glue_job: " + e.__str__()) except Exception as e: raise Exception( "Unexpected error in delete_a_glue_job: " + e.__str__()) print(delete_a_glue_job("transfer_from_s3"))
Output
{'JobName': ' transfer_from_s3', 'ResponseMetadata': {'RequestId': '126adb54-f0a0-4558-b345-d6a4e62674f3', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 27 Feb 2021 15:53:27 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '22', 'connection': 'keep-alive', 'x-amzn-requestid': '126adb54-……….-d6a4e62674f3'}, 'RetryAttempts': 0}}
- Related Articles
- How to use Boto3 to delete a crawler from AWS Glue Data Catalog?
- How to use Boto3 to delete a table from AWS Glue Data catalog?
- How to use Boto3 to paginate through the job runs of a job present in AWS Glue
- How to use Boto3 to delete a specific version of table from AWS Glue Data catalog?
- How to use Boto3 to remove tags from AWS Glue Resources
- How to use Boto3 to get tags from an AWS Glue Resources
- How to use Boto3 library in Python to run a Glue Job?
- How to use Boto3 to add tags in AWS Glue Resources
- How to use Boto3 to check whether a Glue Job exists or not?
- How to use Boto3 to check the status of a running Glue Job?
- How to use Boto3 to get the details of a job that is bookmarked in AWS Glue Data Catalog?
- How to use Boto3 to start a crawler in AWS Glue Data Catalog
- How to use Boto3 to start a trigger in AWS Glue Data Catalog
- How to use Boto3 to stop a trigger in AWS Glue Data Catalog
- How to use Boto3 to start a workflow in AWS Glue Data Catalog
