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

Given an aws-lambda, how can I change the cloudwatch rule associated with it using boto3?

我看过 docs,但我找不到如何更改已安排的活动。这是 serverless.yml 上的示例:

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

使用 boto3,如何以编程方式更改时间表的速率?

摘自我 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 将允许您更改活动日程。