如何使用 Boto3 從 AWS Glue 資料目錄獲取觸發器的詳細資訊
讓我們看看使用者如何從 AWS Glue 資料目錄獲取觸發器的詳細資訊。
示例
獲取在您的賬戶中允許的給定觸發器的詳細資訊 - **'01_PythonShellTest1'**。
解決此問題的方法/演算法
**步驟 1:**匯入 **boto3** 和 **botocore** 異常以處理異常。
**步驟 2:** **trigger_name** 是此函式的必需引數。它將為使用者賬戶獲取給定觸發器的詳細資訊,然後顯示其元資料。
**步驟 3:**使用 **boto3 庫** 建立 AWS 會話。確保在預設配置檔案中提到了 **region_name**。如果未提及,則在建立會話時顯式傳遞 **region_name**。
**步驟 4:**為 **glue** 建立 AWS 客戶端。
**步驟 5:**呼叫 get_trigger 並將 trigger_name 作為 Name 傳遞。
**步驟 6:**它返回給定觸發器的詳細資訊。
**步驟 8:**如果在檢查作業時出現問題,則處理通用異常。
示例程式碼
以下程式碼獲取使用者賬戶中列出的觸發器的詳細資訊:
import boto3
from botocore.exceptions import ClientError
def get_resource_maetadata_of_trigger(trigger_name):
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.get_trigger(Name=trigger_name)
return response
except ClientError as e:
raise Exception("boto3 client error in get_resource_maetadata_of_trigger: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in get_resource_maetadata_of_trigger: " + e.__str__())
a = get_resource_metadat_of_trigger('01_PythonShellTest1')
print(a)輸出
{'Triggers': [{'Name': '01_PythonShellTest1', 'WorkflowName': 'arn:aws:iam::1234:role/dev-edl, 'Id': 'string', 'Type': 'SCHEDULED'|'CONDITIONAL'|'ON_DEMAND', 'State': 'CREATING'|'CREATED'|'ACTIVATING'|'ACTIVATED'|'DEACTIVATING'|'DEACTIVATED'|'DELETING'|'UPDATING', 'Description': 'string', 'Schedule': 'string'
}]}
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP