1

Let's say I have a booking system where I want to fire an aws lambda function to send an email or message to users, 10 minutes before their booking starts. I have looked online and found few solutions.

AWS Lambda + CloudWatch + DynamoDB:

Someone suggested adding the job to dynamodb and setting the TTL to when I want to notify the user and then connect cloudwatch to listen to remove triggers on the dynamodb. I did not like this method as it seems like a hacky way to do it.

ATrigger

This website provides a rest api which you can use to set up a scheduling job in the future. This is exactly what I need but the last update on their social media was in 2018. So probably not maintained.

3

2 Answers 2

1

At a high level, this is a fairly simple architecture.

You have something (we'll call it the Writer) which sends a message to something else (which we'll call the Scheduler). With the message is a time that the Writer wants the Scheduler to forward that message on to an action taker to do something with.

Scheduler Context

You haven't mentioned the Writer, so I assume you already have an idea of what this is, how it works and where it's hosted. You already know that the Action Taker component will be an AWS Lambda (presumably in conjunction with SES or some other SaaS). So it is only the Scheduler component you care about.

You only really have three ways about attacking this, and you have already considered two of them.

  1. Build it yourself

  2. Use a SaaS service

  3. String some existing commodity services together

Let's look at some of the advantages/disadvantages of each.

Build It Yourself

Assuming you are going to do this within AWS, that means building something in EC2, ECS, Fargate, or some other long running environment. It will also need some form of separate data storage, probably an actual database to make sure data doesn't get lost in the event of your container/VM falling over.

On the plus side, you have full control over message structure and you could probably eliminate that Lambda in the Action Taker component and call the email service direct.

But, depending on how you host this new thing you're going to build, you are going to be responsible for writing and maintaining the code, patching OS/platform/etc, making it highly available (i.e. deploying in multiple availability zones) and securing it.

SaaS

In some ways, this would be the perfect solution if you could find a vendor you were happy with. You just send it messages and at the specified time it sends an event. No such standalone service exists in AWS however, so you would need to make that Lambda invokable, probably using AWS API Gateway.

String Some Existing Commodity Services Together

Staying the AWS context, this could be DynamoDB storing messages with a TTL, with a DynamoDB Stream listening for deletions which triggers Action Taker Lambda.

On the plus side, these are all AWS commodity services, so are by default running over multiple Availability Zones, and you are only responsible for managing the configuration, which you shouldn't need to change unless you change the Action Taker component.

On the negative side, this is not a use-case that TTL and DynamoDB streams was built for. Setting a TTL doesn't give to the second accuracy, and could by all account take 48 hours to actually delete something (although it could just take 10 minutes). Then if you have multiple deletes at the same time, the DynamoDB Stream handles those events sequentially.

Here is a link to a blog about where someone built something similar and how it performed.

https://theburningmonk.com/2019/03/dynamodb-ttl-as-an-ad-hoc-scheduling-mechanism/

My advice would be to prefer SaaS over everything else, but if you can't find a vendor you are happy with, then take the time to build something properly yourself.

0
4

I had to tackle a similar problem and depending on the volume of scheduling that needs to happen, an elegant solution would be to use AWS Step Function with a Wait Step, see https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html.

You can configure the step function to wait until a specific timestamp (max 1 year in the future) and it will resume at that specific time. The next step could be to invoke your lambda function that will execute the business logic behind the scheduling.

You do need to consider the limits of AWS Step Functions https://docs.aws.amazon.com/step-functions/latest/dg/limits.html.

1
  • Thank you for your comment @Simon. This is exactly what I ended up doing as it was really simple to implement and worked well with my lambda functions
    – Siyavash
    Commented Aug 27, 2020 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.