gpt4 book ai didi

aws-lambda - 延迟几个小时调用lambda函数

转载 作者:行者123 更新时间:2023-12-04 01:50:09 29 4
gpt4 key购买 nike

我试图找出5小时后调用aws lambda函数的最佳方法是什么。我有另一个lambda函数,该函数将发出多个检索作业以从aws冰川中抓取项目,而且我需要一种解决方案,以便在检索到每个项目时对每个项目运行另一个lambda函数,大约需要5个小时。我当时正在考虑使用sns,但想知道是否还有其他方法可以使用。任何输入表示赞赏。

最佳答案

除了使用CloudWatch之外,您遇到的另一种有趣的方法是使用AWS Step Functions


通过设置一个固定的时间段来使用wait state(或者,如果您将输入数据提供给状态机,则使用一个动态的时间段):

{
"Comment": "An example of the Amazon States Language using wait states",
"StartAt": "WaitState",
"States": {
"WaitState": {
"Type": "Wait",
"Seconds": 10,
"Next": "MyLambda"
},
"MyLambda": {
"Type": "Task",
"Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME",
"End": true
}
}
}

或者,您可以在 task state中将单独的Lambda函数与 choice state结合使用,以在循环中检查其他函数是否应运行:

{
"Comment": "A state machine that submits a Job to AWS Batch and monitors the Job until it completes.",
"StartAt": "Wait X Seconds",
"States": {
"Wait X Seconds": {
"Type": "Wait",
"SecondsPath": "$.wait_time",
"Next": "Get Job Status"
},
"Get Job Status": {
"Type": "Task",
"Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:CheckJob",
"Next": "Job Complete?"
},
"Job Complete?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.status",
"StringEquals": "RUNNING",
"Next": "Wait X Seconds"
},
{
"Variable": "$.status",
"StringEquals": "SUCCEEDED",
"Next": "Do Job"
}
],
"Default": "Wait X Seconds"
},
"Do Job": {
"Type": "Task",
"Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:DoJob",
"End": true
}
}
}

关于aws-lambda - 延迟几个小时调用lambda函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46897859/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com