

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 get the status of a migration operation?
Problem Statement − Use boto3 library in Python to get the status of a migrating operation.
Example − Get the status of migration operation in an account.
Approach/Algorithm to solve this problem
Step 1 − Import boto3 and botocore exceptions to handle exceptions.
Step 2 − Pass the parameter catalog_id whose migrating status needs to check. However, this is an optional parameter. If it is not provided, by default it checks for logged in user account whether migration is in progress or completed. catalog_id is nothing other than user account id.
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 − Call get_catalog_import_status and pass the catalog_id as CatalogId parameter.
Step 6 − It will fetch details of ongoing migrating operation. Otherwise, it will fetch last migration details.
Step 7 − Handle the generic exception if something went wrong while checking the job.
Example
Use the following code to get the status of a migrating operation −
import boto3 from botocore.exceptions import ClientError def status_of_migration(catalog_id = None): session = boto3.session.Session() glue_client = session.client('glue') try: response = glue_client.get_catalog_import_status(CatalogId = catalog_id) return response except ClientError as e: raise Exception( "boto3 client error in status_of_migration: " + e.__str__()) except Exception as e: raise Exception("Unexpected error in status_of_migration: " + e.__str__()) print(status_of_migration())
Output
{'ImportStatus': {'ImportCompleted': True, 'ImportTime': datetime.datetime(2017, 11, 17, 1, 32, 44, tzinfo=tzlocal()), 'ImportedBy': 'StatusSetByDefault'}, 'ResponseMetadata': {'RequestId': '7c33d6f9-……………..-3b202961e3e7', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 21 Feb 2021 05:40:06 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '102', 'connection': 'keep-alive', 'x-amzn-requestid': '7c33d6f9-…….…………-3b202961e3e7'}, 'RetryAttempts': 0}}
- Related Questions & Answers
- How to use Boto3 to check the status of a running Glue Job?
- How to use Boto3 to get the details of a single crawler?
- How to use Boto3 library in Python to get the details of a crawler?
- How to use Boto3 to get the details of multiple triggers at a time?
- How to use Boto3 to get the details of multiple glue jobs at a time?
- How to use Boto3 to get the definition of all the Glue jobs at a time?
- How to use Boto3 to get the list of schemas present in AWS account
- How to use Boto3 to get the details of a classifier from AWS Glue Data catalog?
- How to use Boto3 to get the details of a connection from AWS Glue Data catalog?
- How to use Boto3 to get the details of a database from AWS Glue Data Catalog?
- How to get the details of a workflow using Boto3
- How to use Boto3 to get the list of triggers present in an AWS account
- How to use Boto3 to get the list of workflows present an in AWS account
- How to use Boto3 to get the table definition of a database from AWS Glue Data Catalog?
- How to use Boto3 to get a list of all secrets in AWS Secret Manager