By using AWS re:Post, you agree to the Terms of Use

Is there an Amazon service to schedule future actions?

0

I want to queue a task, probably a REST operation, or SNS, from a lambda. Is there an AWS service that can do that? Lambdas are short lived, so I can't have it hang around for hours in order to start the task. Ideally:

  • when my lambda is called, I can queue the task for execution at some time in the future (2-6 hours, maybe longer with less than 5-10 minute accuracy). I get an ID back if it is scheduled successfully.
  • when my lambda is called again, I can use that ID i got previously, to cancel the task, if I don't need it anymore.

The lambda is getting a bit of data from the calling party, and gets other details from a DynamDB table.

Is there such a thing? (replies below indicate that Step Functions may be a good option)

I need to be able to create these on the fly, one for every user, which may scale to 1 million. I'm curious if the cost of that would outweigh an EC2 instance that runs all the time and sends out the tasks when needed. This is what the EC2 could do:

  • DynamoDB gets updated, and a field is set indicating that the user needs a notification in 4 hours. (2-6 hours user selected range)
  • DynamoDB may get updated again, and that field is changed to reset the delay back to 4 hours. (2-6 hours user selected range)
  • every 5-10 minutes, IC2 system will query for a DynamoDB key with a sort of "time to notify", and if that time to notify is close or past, then send a notification to the user.

Instead of:

  • DynamoDB gets updated, and a field is set indicating that the user needs a notification in 4 hours. (2-6 hours user selected range)
  • Lambda schedules a future event (using Step Function?)
  • DynamoDB may get updated again, and that field is changed to reset the delay back to 4 hours. (2-6 hours user selected range)
  • Lambda cancels the last future event and schedules a new future event
  • Future event triggers, and calls a lambda that then calls SNS and sends out the notification The normal case is that the notification never goes out, because the event keeps getting postponed to later times.

An alternative:

  • DynamoDB gets updated, and a field is set indicating that the user needs a notification in 4 hours. (2-6 hours user selected range)
  • DynamoDB may get updated again, and that field is changed to reset the delay back to 4 hours. (2-6 hours user selected range)
  • Every 5 minutes, a single lambda runs, queries DynamoDB for users who need notification at that moment, and calls SNS for each of those

In this case, the lambda runs only 288 times a day regardless of the number of users. (I doubt that a lambda can trigger about 1,000 SNS messages during its short invocation time.)

asked 6 months ago58 views
2 Answers
0

One way to do this would be to use Lambda but trigger it using a scheduled CloudWatch Event. That's not really event queuing though but you could have your code create the schedule on demand.

Another way would be to use a DynamoDB table; create the event you need as a record but set an expiry time on that record. When it expires an event will be sent to (again) Lambda. Note that the event might not be created immediately though - it can be delayed by up to 48 hours so may not be handy if you need precise timing.

Please reach out yo your local AWS Solutions Architect - this sounds like an excellent idea for an product or service.

profile picture
EXPERT
answered 6 months ago
  • How does one find the local AWS Solutions Architect?

0

There are also other Options to do that depending on the requirements.

If you are fine with a delay of max 15 Minutes i would use an SQS Queue. When putting the message in the queue you can define a delay of up to 900 seconds.

Another option is to use a StepFunction for this and to use the Wait-State. This is more flexible and you get an id for the execution from the service call. And you get also a nice UI where you can see all running processes and all processes ready.

answered 6 months ago
  • I'm looking for delays of 2-6 hours based on user preference. I had discovered the Step Function, and will look into it. Before that I was looking at CloudWatch events rule.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions