如何使用Python/Boto3在AWS EventBridge中启用/禁用规则



如何启用/禁用调度Lambda函数的事件桥规则。

长期目标是在某些假期取消时间表,所以我的下一个任务是看看是否有好的假期/管理图书馆。第一个任务只是看看我是否可以从python程序中启用/禁用事件桥规则。

我第一次使用这条线是在我工作的S3测试中:

s3_resource = boto3.resource('s3') 

并将其更改为

resource = boto3.resource('events') 

它返回了以下错误:boto3.exceptions.ResourceNotExistsError:"events"资源不存在。可用资源有:

  • 云层形成
  • cloudwatch
  • 发电机数据库
  • ec2
  • 冰川
  • iam
  • opsworks
  • s3
  • sns
  • sqs

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/events.html#eventbridge

我用pip升级了我的boto版本1.17.57。

pip install boto3 --upgrade -t . 
pip install botocore --upgrade -t . 

我在本地安装了,所以我最终可以将其压缩到Lambda函数中。我不得不将资源更改为客户端作为方法。

import uuid
import boto3
import os
import pprint
client = boto3.client('events') 
action = "enable"
myRulename = 'PolygonIOAPIDataCollectorMarketHours'
if action == "enable":
response = client.enable_rule(
Name=myRulename
)
else:
response = client.disable_rule(
Name=myRulename
)
pprint.pprint(response)

第一次运行时,我遇到了一个安全错误,不得不向IAM用户添加一个策略。

它返回:

{'ResponseMetadata': {'HTTPHeaders': {'content-length': '0',
'content-type': 'application/x-amz-json-1.1',
'date': 'Wed, 09 Sep 2020 02:01:32 GMT',
'x-amzn-requestid': '6d1de8cc-1c82-4a7f-956a-ad33e6e8c899'},
'HTTPStatusCode': 200,
'RequestId': '6d1de8cc-1c82-4a7f-956a-ad33e6e8c899',
'RetryAttempts': 0}}

最新更新