pythoncronaws-lambdaamazon-cloudwatchcloudwatch

AWS Lambda function with multipal cron expressions


I wrote 4 lambda functions in Python, one stops my dev instances at 19p.m from monday to friday, second function starts them at 7a.m from monday to friday, the third function stops the test instances at 17p.m all days of the week and the forth function starts them at 8a.m all days of the week.

I put cloudWatch as a trigger and I created a rule with the cron expression for each one of them.

I wonder, if there is any way to put them all together in only one function, and specify the cron expression in python inside the function ? If that's possible what would be the trigger here? Thank you.

Edited by: Cloudgls on Nov 16, 2016 12:29 PM


Solution

  • You could just have a single CloudWatch alarm trigger hourly and the Lambda function could check to see if any scheduled tasks need to run. If any evaluate to true then execute them.