从另一个Lambda调度Lambda。

huangapple go评论61阅读模式
英文:

Schedule Lambda from another Lambda

问题

当A函数成功执行后,我希望在24小时后执行B函数。是否可以实现?如果可以,如何实现?

英文:

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?

答案1

得分: 2

有多种使用AWS资源实现这一目标的方法。以下是一些可以轻松实现的选项:

Step Functions(步骤函数): 在步骤函数中,您可以利用Wait(等待)状态来控制消息从一个Lambda函数转移到另一个Lambda函数的过渡。通过配置适当的等待时间,您可以实现Lambda函数A和Lambda函数B之间所需的延迟。

SQS: 另一种方法是使用SQS消息触发Lambda函数B。但是,请注意,SQS的最大可见性超时限制为12小时。要实现24小时的窗口,您可以在SQS上启用重试功能。但是,为了触发重试,您需要配置Lambda函数B,在第一次尝试处理来自SQS队列的消息时引发异常。这将告诉SQS应重新尝试消息处理。

英文:

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.

答案2

得分: 0

Your lambda A 可以在 SQS 中发布消息,然后您的 lambda B 可以每小时执行一次(使用 Cloudwatch 事件桥),并读取 SQS 队列中的消息,如果检测到消息并且已发布了 24 小时,您可以继续执行 lambda B 并从 SQS 中删除该消息。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月10日 23:56:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76220486.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定