如何使用 Boto3 啟動 AWS Glue 資料目錄中的觸發器
在本文中,我們將瞭解使用者如何在 AWS Glue 資料目錄中啟動觸發器。
示例
問題陳述:使用 Python 中的 boto3 庫啟動觸發器。
解決此問題的方法/演算法
步驟 1:匯入 boto3 和 botocore 異常以處理異常。
步驟 2:trigger_name 是此函式中的引數。
步驟 3:使用 boto3 庫建立 AWS 會話。確保在預設配置檔案中提到了 region_name。如果未提及,則在建立會話時顯式傳遞 region_name。
步驟 4:為 glue 建立 AWS 客戶端。
步驟 5:現在使用 start_trigger 函式並將引數 trigger_name 作為 Name 傳遞。
步驟 6:它返回響應元資料並啟動觸發器,而不管其計劃如何。
步驟 7:如果啟動觸發器時出現問題,則處理通用異常。
示例程式碼
以下程式碼在 AWS Glue 資料目錄中啟動觸發器:
import boto3
from botocore.exceptions import ClientError
def start_a_trigger(trigger_name)
session = boto3.session.Session()
glue_client = session.client('glue')
try:
response = glue_client.start_trigger(Name=trigger_name)
return response
except ClientError as e:
raise Exception("boto3 client error in start_a_trigger: " + e.__str__())
except Exception as e:
raise Exception("Unexpected error in start_a_trigger: " + e.__str__())
print(start_a_trigger("test-daily"))輸出
{'Name': 'test-daily', 'ResponseMetadata': {'RequestId': 'b2109689-*******************-d', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 28 Mar 2021 08:00:04 GMT', 'content-type': 'application/x-amz-json-1.1', 'content-length': '26', 'connection': 'keep-alive', 'x-amzn-requestid': 'b2109689-***********************-d'}, 'RetryAttempts': 0}}
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP