0
votes

My goal is to run an AWS Lambda Function on a recurring schedule. However, that schedule is not compatible with CRON so CloudWatch Schedule Event Rules are not an option (to my understanding).

Specifically, I'm trying to have it run on the 5th working day. That needs to take into account weekends, holidays, and custom scheduled down-time that varies from month to month.

What is the recommended approach for running a Lambda function on a recurring schedule without actually using a CRON expression?

There are a couple workarounds that I can think of which I'll list below.

  1. Create a CloudWatch event that runs on every weekday. Have that trigger a Lambda that will check if it is not a holiday or scheduled downtime. If it's a valid day, it'll push a value to an SQS Queue. Once that Queue reaches 5 values in the queue, it'll empty the queue and trigger the Lambda I described above. If the Lambda fails, it'll then push to a DLQ.
  2. For simplicity, have the same exact thing as above but instead run it every day instead of every weekday and just perform that same check there instead.
1
Where do the rules for holidays and custom down time come from?stdunbar
IMO you're workarounds sound fine to me. You could probably avoid a 2nd lambda/SNS queue by just having your lambda run everyday and only do it's action if it meets your scheduling criteria. If you just store the the last execution date somewhere like a dynamodb table, your lambda function should have all the info it needs to determine if it should perform its actionjordanm
I agree, simply go with the workaround 2.luk2302

1 Answers

0
votes

I think one question I'd have here is if the list of holidays or "non-working" days is pre-compiled?

Assuming you can pre-compile the list of holidays, it should be relatively straight-forward to compile an array of "non-working" days. From there you would need to store the day it last ran somewhere (maybe DynamoDB?) and run the function every day. The function would need to check if it's been five working days since the last run and if it has, then run.

I'm not sure the use case for this but if you have the option to just run it every day then that would be far simpler. If not, does it absolutely have to be every 5 working days? Could you use a cron based expression and just do once a week?