繁体   English   中英

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

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

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

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

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

取自我博客中的这个例子

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将允许您更改事件时间表。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM