इस लेख में, हम देखेंगे कि उपयोगकर्ता AWS खाते में मौजूद सभी क्रॉलर्स की सूची कैसे प्राप्त कर सकता है।
उदाहरण
समस्या कथन: सभी क्रॉलर्स की सूची प्राप्त करने के लिए पायथन में boto3 लाइब्रेरी का उपयोग करें।
इस समस्या को हल करने के लिए दृष्टिकोण/एल्गोरिदम
चरण 1: अपवादों को संभालने के लिए boto3 और botocore अपवाद आयात करें।
चरण 2: इस फ़ंक्शन में कोई पैरामीटर नहीं हैं।
चरण 3: boto3 लाइब्रेरी का उपयोग करके AWS सत्र बनाएं। सुनिश्चित करें कि डिफ़ॉल्ट प्रोफ़ाइल में region_name उल्लिखित है। यदि नहीं, तो सत्र बनाते समय स्पष्ट रूप से region_name पास करें।
चरण 4: glue के लिए AWS क्लाइंट बनाएं।
चरण 5: अब list_crawlers का उपयोग करें
चरण 6: यह AWS Glue डेटा कैटलॉग में मौजूद सभी क्रॉलर्स की सूची लौटाता है।
चरण 7: जॉब की जांच करते समय यदि कुछ गलत हुआ तो सामान्य अपवाद को संभालें।
उदाहरण कोड
निम्न कोड सभी क्रॉलर्स की सूची प्राप्त करता है -
import boto3
from botocore.exceptions import ClientError
def list_of_crawlers():
session = boto3.session.Session()
glue_client = session.client('glue')
try:
crawler_details = glue_client.list_crawlers()
return crawler_details
except ClientError as e:
raise Exception("boto3 client error in list_of_crawlers: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in list_of_crawlers: " + e.__str__())
print(list_of_crawlers())
आउटपुट
{'CrawlerNames': ['crawler_for_s3_file_job', 'crawler_for_employee_data', 'crawler_for_security_data'], 'ResponseMetadata': {'RequestId': 'a498ba4a-7ba4-47d3-ad81-d86287829c1d', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 13 Feb 2021 14:04:03 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '830', 'connection': 'keep-alive', 'x-amzn-requestid': 'a498ba4a-7ba4-47d3-ad81-d86287829c1d'}, 'RetryAttempts': 0}}