【问题标题】:Given an aws-lambda, how can I change the cloudwatch rule associated with it using boto3?给定一个 aws-lambda,我如何使用 boto3 更改与之关联的 cloudwatch 规则?
【发布时间】:2019-02-13 04:39:00
【问题描述】:
我已经看到docs,但我找不到如何更改已安排的活动。这是serverless.yml 上的示例:
schedule_customer_processing:
handler: fetch-downloadable-client-data/adyen/schedule_customer_processing.schedule
events:
- schedule: rate(15 minutes)
使用 boto3,我如何以编程方式更改计划的速率?
【问题讨论】:
标签:
python
amazon-web-services
aws-lambda
boto3
serverless-framework
【解决方案1】:
取自我blog中的这个例子
REGULAR_SCHEDULE = 'rate(20 minutes)'
WEEKEND_SHEDULE = 'rate(1 hour)'
RULE_NAME = 'My Rule'
def reschedule_event():
"""
Cambia la planificación de la lambda, para que descanse los findes :D
"""
sched = boto3.client('events')
current = sched.describe_rule(Name=RULE_NAME)
if is_weekend() and 'minutes' in current['ScheduleExpression']:
sched.put_rule(
Name=RULE_NAME,
ScheduleExpression=WEEKEND_SCHEDULE,
)
if not is_weekend and 'hour' in current['ScheduleExpression']:
sched.put_rule(
Name=RULE_NAME,
ScheduleExpression=REGULAR_SCHEDULE,
)
致电shed.put_rule 可让您更改活动日程。