J.Rogers
J.Rogers

Reputation: 51

AWS Lambda Multiple invocations with a random delay

I'm in the process of migrating an existing NodeJS application to run as a Lambda function. So far I've identified that the main function which sends an HTTP POST request can be placed into a Lambda function, however, this function is invoked via a For Loop in which after each iteration has a random delay. The For Loop's iteration count is defined by a user request.

The only way I can think of is having a normal NodeJS process that runs the "Loop" which invokes the lambda. But this defeats the purpose of the serverless/auto-scaling architecture I am trying to create.

Am I able to replace the below for loop & random delay with a serverless/auto-scaling solution?

  for (let i = 0; i < userTasks; i++) {
    httpRequestLambda();
    await delay(); // delay can be anywhere from 5 Seconds to 20 Minutes 
  }

Upvotes: 0

Views: 652

Answers (1)

amitd
amitd

Reputation: 1532

These are following options you can schedule AWS Lambda;

  1. Schedule AWS Lambda Functions Using CloudWatch Events

  2. Schedule AWS Lambda Functions Using EventBridge

Overview of option 1) and option 2) is also available on this AWS blog with AWS web-console screen-shots.

  1. Schedule a Serverless Workflow with AWS Step Functions and Amazon CloudWatch. You can also add delay as mentioned in this sample Task Timer project.

Upvotes: 1

Related Questions