给定aws-lambda,如何使用boto3更改与其相关的cloudwatch规则?

时间:2019-02-12 19:55:44

标签: python amazon-web-services aws-lambda boto3 serverless-framework

我见过docs,但是找不到如何更改预定事件。这是serverless.yml上的示例:

schedule_customer_processing:
    handler: fetch-downloadable-client-data/adyen/schedule_customer_processing.schedule
    events:
     - schedule: rate(15 minutes)

使用boto3,如何以编程方式更改计划的费用?

1 个答案:

答案 0 :(得分: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将允许您更改事件时间表。