如何使用 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