简体   繁体   中英

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

I've seen the docs , but I can't find how to change the scheduled event. Here's the example on serverless.yml :

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

Using boto3, how can I change the rate of the schedule programmatically?

Taken from this example in my 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,
        )

Calling shed.put_rule will allow you to change the event schedule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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