How to make lambda function wait a certain time to be executed? I used time.sleep(), but it doesn't work

0

How to make lambda function wait a certain time to be executed? I used time.sleep(), but it doesn't work I want Lambda to take s objects from the bucket and send it to another bucket, but at a certain time, I want it to take an object and then it takes 5s to send another object.

  • I'm curious, why do you need to include a 5-second wait between sending to the other bucket?

2 個答案
3
已接受的答案

Use a Step Function. A Wait state allows the step function to wait for a specified time interval - https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html

You can then create a Task to invoke the lambda function - https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html

profile pictureAWS
專家
已回答 1 年前
profile pictureAWS
專家
已審閱 1 年前
2

You can't really wait for a Lambda function to be executed. You need to define what is the trigger that invokes the function. I am not sure what exactly you are trying to do, but I think you have a few options:

  1. You can use EventBridge scheduled events if you need to invoke a function on some schedule.
  2. Send a delayed messages to SQS with a Lambda trigger.
  3. Launch a state machine and use a wait state.
profile pictureAWS
專家
Uri
已回答 1 年前
profile pictureAWS
專家
已審閱 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南