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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则