0

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!

Niko
  • 3
  • 1

1 Answers1

0

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.

fedonev
  • 20,327
  • 2
  • 25
  • 34
  • Thanks, that makes perfect sense! I was looking to avoid that (in my head) thinking it would be too costly to check, but just popped into a cost calculator and didn't realise just how ridiculously cheap they can be. Appreciate it. – Niko Nov 18 '21 at 17:07