如何使用 Boto3 從 AWS Glue 資料目錄中刪除爬蟲?
問題陳述 − 使用 Python 中的 boto3 庫刪除在您的賬戶中建立的爬蟲。
示例 − 刪除在您的賬戶中建立的名為“Portfolio”的爬蟲。
解決此問題的方法/演算法
步驟 1 − 匯入 boto3 和 botocore 異常以處理異常。
步驟 2 − 傳遞要從 AWS Glue 目錄中刪除的爬蟲名稱引數 `crawler_name`。
步驟 3 − 使用 boto3 庫建立 AWS 會話。確保在預設配置檔案中提到了 `region_name`。如果未提及,則在建立會話時顯式傳遞 `region_name`。
步驟 4 − 為 Glue 建立 AWS 客戶端。
步驟 5 − 現在使用 `delete_crawler` 函式並將 `crawler_name` 作為 `Name` 引數傳遞。
步驟 6 − 它將刪除爬蟲並返回響應元資料。
步驟 7 − 如果在檢查作業時出現問題,則處理通用異常。
示例
使用以下程式碼從 AWS Glue 資料目錄中刪除爬蟲:
import boto3
from botocore.exceptions import ClientError
def delete_a_crawler(crawler_name):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.delelte_crawler(Name=crawler_name)
return response
except ClientError as e:
raise Exception( "boto3 client error in delete_a_crawler: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in delete_a_crawler: " + e.__str__())
print(delete_a_crawler("Portfolio"))輸出
{'ResponseMetadata': {'RequestId': '067b667f-0a74d4f30a5b',
'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sat, 27 Feb 2021
14:54:30 GMT', 'content-type': 'application/x-amz-json-1.1', 'contentlength': '2', 'connection': 'keep-alive', 'x-amzn-requestid': '067b667f0a10-4f99-91be-0a74d4f30a5b'}, 'RetryAttempts': 0}}
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP