0

Say I have a messaging application. Every minute I want the application to send push notifications if any message is one minute old. Currently, I'm thinking of having a lambda function being called every minute, but since I'm probably not going to have a push notification to send every minute, I was wondering if it was possible to schedule a lambda function to run in the future whenever a message is added to the system.

Basically, it would work like this:

  1. Message arrives to system.
  2. Is a lambda function scheduled to notify of stale messages?
  3. If no, schedule lambda function
  4. If yes, do nothing
  5. When lambda has executed, check if there are more messages in system that haven't gone stale yet.
  6. If yes, schedule lambda function.
helloV
  • 42,534
  • 4
  • 100
  • 125
Robin Heggelund Hansen
  • 4,716
  • 6
  • 32
  • 51

1 Answers1

0

Seems like this would be a good candidate for SNS(Simple Notification Service). Your application can push its notifications to SNS with a payload which would then trigger your lambda function(with the payload) whenever that message comes in.

See: http://docs.aws.amazon.com/sns/latest/dg/sns-lambda.html

Ryan
  • 5,177
  • 30
  • 27
  • Can this be done in a delayed manner? I don't want to start a lambda whenever a new message comes in, but 60 seconds later. – Robin Heggelund Hansen Feb 24 '16 at 14:56
  • 1
    Ah, I see now. Unfortunately I think the only way to use the built in lambda scheduling is in the console. SQS has delayed queues(http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-delay-queues.html) but you can't call Lambda from SQS. There is probably some combination of SNS + SQS + Lambda to make this work. I'll have to take another look at this later. – Ryan Feb 24 '16 at 18:10
  • I think this question provides possible solutions https://stackoverflow.com/q/41557956/3484824 – Can Rau May 04 '20 at 07:00