Trigger the second Lambda function 2 hours later after the first one successfully has executed successfully

Hi All,

Currently I have two Lambda functions (A, and B). I am trying to build the workflow that A is doing some changes on some AWS resources and keep it for 2 hours, while 2 hours later, B change the config of those AWS resources back to the initial state. Is there a flexible way to do that? Since the function A is triggered by a Cron function. I am also considering is the step function is the solution to my scenario? Thanks.

Best.

Hi KanesYang,

It sounds like Step Functions would be the best way to handle this situation. You can add a wait step for 2 hours and then Step Functions will continue on and invoke Function B. The alternative way you could handle this is for Function A to create a CloudWatch Event for 2 hours later that invokes Function B. Once Function B has completed its tasks it would delete the CloudWatch Event.

First option is a cleaner approach.

3 Likes

use step functions or use dynamodb streams with a 2 hours TTL items

Read more about it here
https://theburningmonk.com/2019/03/dynamodb-ttl-as-an-ad-hoc-scheduling-mechanism/

2 Likes