Han Van Pham
Han Van Pham

Reputation: 490

How to run a AWS Lambda after 2 hours

I have 2 Lambda, The first Lambda for loading data into my GBQ, And the second Lambda need to be run after that 2 hours to check the data on GBQ. I have investigated it but seems like we can schedule using Rate or Cron, but I want to run the second Lambda only once. Is there another way to do it? Thank you.

Upvotes: 3

Views: 1932

Answers (2)

Harsh Manvar
Harsh Manvar

Reputation: 30113

Rate and corn is one option with adding the cloud watch with the Lambda function but according to your requirement you can make it something like

When lambda one trigger and complete execution you can add code with endpoint of another lambda. as you want to run it after two hour you can set time using node-cron.so one lambda one will be trigger after that it will trigger lambda two function using the end point where time of 2 hour manage by node-cron.

if you are using python then you can use a scheduler

import schedule
import time

def job():
    print("I'm working...Triggering another lambda end point")

schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)

while 1:
    schedule.run_pending()
    time.sleep(1)

Upvotes: 1

anhlc
anhlc

Reputation: 14439

According to your requirement, you can use AWS Step Functions Wait state to coordinate the two lambda functions:

https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html

Upvotes: 3

Related Questions