Home > Blockchain >  Am I able to use AWS EventBridge (or alternative) in order to re-run a lambda after an hour if the p
Am I able to use AWS EventBridge (or alternative) in order to re-run a lambda after an hour if the p

Time:11-19

I have written a lambda using Python which is dependent upon external APIs which can occasionally go down. This is triggered once a day using EventBridge to gather data from yesterday, and updates a file in S3 at the same time every day.

I was wondering how I would be able to re-run the Lambda, which includes a check as to whether the external API is functioning at the start, every 1-2 hours for the rest of the day until it successfully works? It would need to stop at 11pm so as to not go into the next calendar day.

Specifically I am using the Google Search Console API which should have updated every 4 hours but hasn't in this case for 30.

Appreciate the help!

CodePudding user response:

A CloudWatch event schedule can trigger your lambda periodically throughout the day. Using a cron expression, you can have your lambda invoked at suitable intervals.

The lambda first looks up the last_modified property on the target S3 file. If last_modified is not today, proceed and call the API. If last_modified is today, we have nothing to do, so the lambda returns without doing anything.

  • Related