1

I've currently got a function in lambda that when invoked sends a message to a user who invoked it. 2 days later I would like to send a follow up message. All the code to send the actual messaging works fine.

I'm using Lambda due to the auto-scaling abilities, and ideally I want to avoid having to set-up a separate database to store the userId, timestamp of the original interaction (so I can work out the follow up time) and follow up message for 2 days later. The reason for this is due to scaling as I'm not sure when the peaks are going to be. This is a short frame project but it's expecting high engagement, but at unknown,varied times.

I'd initially thought about SNS to call another lambda function with the data, however, I've since discovered that SNS doesn't support scheduled messages. Ideally I'd also like not to involve polling another service. Are there any good solutions for this?

I realise not using a DB is a strong limitation and if I have to use one then I'll use one, but still not having to poll would be useful (I guess I could schedule a lambda function and create an index on the timestamp in dynamodb)

TommyBs
  • 179
  • 2
  • 10

1 Answers1

0

Recently announced AWS Step Functions service could help you to implement what you are describing. The service can coordinate execution of your application components what may be e.g. Lambda functions. It provides you a graphical console where you can model dependencies between them and to define a finite state machine which captures the application workflow. You can find more information about the service at the following links:

AWS Step Functions

Announcing AWS Step Functions

Back to your case. Step Functions provides you a Wait state which delays the state machine from continuing for a specified time. So your application workflow may look like this:

enter image description here

The FirstState state would executes a lambda function send a message to a user who invoked it. Then, it would wait 2 days, represented by wait_using_seconds state, and finally it would execute a lambda function 'send a follow up message,' as FinalState state.

Definition of the state machine written in Amazon States Language:

{
  "Comment": "An example of the Amazon States Language using wait states",
  "StartAt": "FirstState",
  "States": {
    "FirstState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT:function:FUNCTION1",
      "Next": "wait_using_seconds"
    },
    "wait_using_seconds": {
      "Type": "Wait",
      "Seconds": 172800,
      "Next": "FinalState"
    },

    "FinalState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT:function:FUNCTION2",
      "End": true
    }
  }
}
dsmsk80
  • 5,757
  • 17
  • 22