Roopchand
Roopchand

Reputation: 39

Schedule Lambda from another Lambda

I have two lambda function and both written in Java. Assume A & B.. When A function got successfully executed then I want B function to be executed after 24 hours. Is it possible to achieve? If yes how?

Upvotes: 0

Views: 95

Answers (2)

codeninja.sj
codeninja.sj

Reputation: 4129

There are multiple ways to achieve this using AWS resources. Here are a few options that can be implemented easily:

Step Functions: In Step Functions, you can utilize the Wait state to control the transition of messages from one Lambda function to another. By configuring appropriate wait times, you can achieve the desired delay between the execution of Lambda function A and Lambda function B.

SQS: Another approach is to trigger Lambda function B using SQS messages. However, note that the maximum visibility timeout for SQS is limited to 12 hours. To achieve a 24-hour window, you can enable the retry functionality on the SQS. However, in order to trigger the retries, you would need to configure Lambda function B to throw an exception during the first attempt of processing the messages from the SQS queue. This will signal to SQS that the message processing should be retried.

Upvotes: 2

Miguel Conde
Miguel Conde

Reputation: 853

Your lambda A can publish a message in SQS, then your lambda B can be executed each one hour (using Cloudwatch event bridge) and reading the messages in the SQS queue, if a message is detected and have 24 hours published you can continue with the execution of the lambda B and delete the message from SQS.

Upvotes: 0

Related Questions