如何使用Boto3停止AWS Glue数据目录中的触发器

如何使用Boto3停止AWS Glue数据目录中的触发器

在本文中,我们将看到用户如何停止AWS Glue数据目录中的触发器。

更多Python相关文章,请阅读:Python 教程

示例

问题陈述: 使用Python中的 boto3 库停止触发器。

解决这个问题的方法/算法

  • 第一步: 导入 boto3botocore 异常来处理异常。

  • 第二步: 触发器名称是此函数中的参数。

  • 第三步: 使用 boto3 lib 创建AWS会话。 确保默认配置文件中提到了 region_name 。 如果没有提到,那么在创建会话时显式传递 region_name

  • 第四步:glue 创建AWS客户端。

  • 第五步: 现在使用 stop_trigger 函数,并将参数 trigger_name 作为Name传递。

  • 第六步: 它返回响应元数据并停止触发器。

  • 第七步: 如果在停止触发器时出现了错误,请处理通用异常。

示例代码

以下代码停止AWS Glue数据目录中的触发器 –

import boto3
from botocore.exceptions import ClientError

def stop_a_trigger(trigger_name)
   session = boto3.session.Session()
   glue_client = session.client('glue')
   try:
       response = glue_client.stop_trigger(Name=trigger_name)
       return response
   except ClientError as e:
       raise Exception("boto3 client error in stop_a_trigger: " + e.__str__())
   except Exception as e:
       raise Exception("Unexpected error in stop_a_trigger: " + e.__str__())
print(stop_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}}

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程