0

I have an AWS Lambda that polls from an external server for new events every 6 hours. On every call, if there are any new events, it publishes the updated total number of events polled to a SNS. So I essentially need to call the lambda on fixed intervals but also pass a counter state across calls. I'm currently considering the following options:

  • Store the counter somewhere on a EFS/S3, but it seems an overkill for a simple number
  • EventBridge, which would be ok to schedule the execution, but doesn't store state across calls
  • A step function with a loop + wait on the the lambda would do it, but it doesn't seem to be the most efficient/cost effective way to do it
  • use a SQS with a delay so that the lambda essentially triggers itself, passing the updated state. Again I don't think this is the most effective, and to actually get to the 6 hours delay I would have to implement some checks/delays within the lambda, as the max delay for SQS is 15 minutes

What would be the best way to do it?

apocalypsis
  • 520
  • 8
  • 19

1 Answers1

1

For scheduling Lambda at intervals, you can use CloudWatch Events. Scheduling Lambda using Serverless framework is a breeze. A cronjob type statement can schedule your lambda call. Here's a guide on scheduling: https://www.serverless.com/framework/docs/providers/aws/events/schedule

As for saving data, you can use AWS Systems Manager Parameter Store. It's a simple Key value pair storate for such small amount of data.

https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html

OR you can also save it in DynamoDB. Since the data is small and frequency is less, you wont be charged much and there's no hassle of reading files or parsing.

Hussain Mansoor
  • 2,934
  • 2
  • 27
  • 40