0

I have a database consisting of many items. At least one time per day I want to loop through all items in this database and for each item, call an external API to fetch current data about this item and store it in my database.

With this scenario in mind, I was thinking of using Lambda, DynamoDB and SNS in the following way:

  • Scheduled Lambda (worker) that loops through all items in the DynamoDB
  • For each item, publish to a SNS topic with details about that specific item
  • Another Lambda (consumer/processer) listens to that SNS topic to get each item
  • For each item received, perform request to external API and update the item in DynamoDB

This setup should be scalable, easy to use/configure/maintain and hopefully cost efficient as well. But will it handle if the DynamoDB has 1000+ items to loop through at least once every day? Is there fault tolerance with this setup? Will it handle if I want to trigger this more than once every day, and more importantly; will it still be cost efficient if triggered say once every hour? Is there a better way of doing this?

Somehow I feel I should use SQS but maybe it's not really useful when running serverless since you can't poll the queue to fetch new items to process?

  • I'm not a lambda expert, but lambda seems appropriate and cost effective no matter how often you want to run this. Maximum lambda run time is 5 minutes, so one master process that queues everything then many lambda workers seems appropriate. Queue pattern based on a timer here. Another option could be a DynamoDB property / control table that keeps state, but consider DynamoDB costs. – Tim May 20 '18 at 19:06
  • Thank you @Tim for affirming my setup :) Regarding SQS, what would be the advantage of adding it into the mix? Since it's not working out of the box with serverless setups like Lambda and I'm not sure if that extra trouble brings me something substantial? Also, is there any other solution you would recommend over DynamoDB instead? Thanks! – Tanax May 20 '18 at 19:52
  • I misread, though you said SQS. SNS is supported by Lambda which is easier, though logically SQS might better you can't easily trigger Lambda with SQS, – Tim May 20 '18 at 20:42
  • Thank you @Tim. I agree, SNS just makes it a lot easier to use with Lambda than SQS. Is there anything I will "lose" by going with SNS rather than SQS in this case? And is Dynamo still the best option to use in this case? Thanks :) – Tanax May 21 '18 at 16:09
  • 1
    SQS is now supported on Lambda apparently so I guess I can just use SQS now instead :) aws.amazon.com/blogs/aws/… – Tanax Jun 29 '18 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.