AWS Lambda. Invoke with delay

Viewed 5518

I need to build "tasks scheduler" with Amazon tools. Main problem that i need execute task once with huge delay (it may be a few hours or few weeks).

I try to research how to build it with CloudWatch and Lambda function. As i understand - i need to use separate rule for one timeout execution. But AWS allow me only 100 rules/account.

Probably i'm going wrong way and this tools not intended for my task.

Also i tried SQS, but it did't allow me to set timeout more than 15 minutes. The simplest way - use own mircoservice with crone, but i hope that it is possible to do it in cloud )

May be someone has the same issue and can share with me thoughts about the implementation of this?

5 Answers

You may be able to use AWS Step Functions Wait State for this. I haven't used it myself but it seems like you can define a state machine where the result of a lamdba function can be used to determine how long to wait until the next step function.

Alternatively, my API https://posthook.io is able to make HTTP POST requests to defined endpoints at specific times.

As someone pointed out earlier you can use the AWS step function, A sample definition that will delay lambda execution for the specified time period. You can trigger this step function from cloud watch event rules targets or event bridge

{
  "Comment": "An example of the Amazon States Language using wait states",
  "StartAt": "wait_using_seconds",
  "States": {
    "wait_using_seconds": {
      "Type": "Wait",
      "Seconds": 450, // time to delay
      "Next": "FinalState"
    },
    "FinalState": {
     "Type": "Task",
      "Resource": "arn:aws:lambda:<region>:<account-name>:function:<function-name>",
      "End": true
    }
  }
}

If you have any flexibility to use a cloud provider other than AWS, the Google Cloud Tasks API can provide the functionality you're looking for. There's a simple demonstration web service built using this API at https://delayedrequest.com

Related