Amazon web services 阶跃函数中的循环
我试图在循环中调用我的step函数中的几个步骤,但我无法理解我需要如何做。到目前为止,我所拥有的是:我需要添加另一个lambda函数(GetReviews),它将在循环中调用CreateReview、SendNotification。我该怎么做呢? 我指的是“”文件,它表明这是可能的 步进函数定义:Amazon web services 阶跃函数中的循环,amazon-web-services,aws-lambda,aws-step-functions,Amazon Web Services,Aws Lambda,Aws Step Functions,我试图在循环中调用我的step函数中的几个步骤,但我无法理解我需要如何做。到目前为止,我所拥有的是:我需要添加另一个lambda函数(GetReviews),它将在循环中调用CreateReview、SendNotification。我该怎么做呢? 我指的是“”文件,它表明这是可能的 步进函数定义: { "Comment": "Scheduling Engine", "StartAt": "CreateReview", "States": { "CreateReview":
{
"Comment": "Scheduling Engine",
"StartAt": "CreateReview",
"States": {
"CreateReview": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-west-2:529627678433:function:CreateReview",
"Next": "CreateNotification",
"InputPath": "$",
"ResultPath": "$.CreateReviewResult",
"OutputPath": "$"
},
"CreateNotification": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-west-2:529627678433:function:CreateNotification",
"InputPath": "$",
"ResultPath": "$.CreateNotificationResult",
"OutputPath": "$",
"End": true
}
}
}
很抱歉回复太晚。你可能已经解决了这两者之间的问题,但你来了 因此,在步骤函数中循环时,我只需添加一个选择状态(请参阅) 其中一个状态需要输出是否已完成循环,或者迭代的项目数和项目总数 在第一种情况下,可能是这样的
{
"Comment": "Scheduling Engine",
"StartAt": "CreateReview",
"States": {
"GetReviews": {
whatever
"Next": "LoopChoiceState"
},
"LoopChoiceState": {
"Type" : "Choice",
"Choices": [
{
"Variable": "$.loopCompleted",
"BooleanEquals": false,
"Next": "GetReviews"
}
],
"Default": "YourEndState"
},
"CreateReview": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-westz2:529627678433:function:CreateReview",
"Next": "CreateNotification",
"InputPath": "$",
"ResultPath": "$.CreateReviewResult",
"OutputPath": "$"
},
"CreateNotification": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-west-2:529627678433:function:CreateNotification",
"InputPath": "$",
"ResultPath": "$.CreateNotificationResult",
"OutputPath": "$",
"End": true
}
}
}
第二种情况:
{
"Comment": "Scheduling Engine",
"StartAt": "CreateReview",
"States": {
"GetReviews": {
whatever
"Next": "LoopChoiceState"
},
"LoopChoiceState": {
"Type" : "Choice",
"Choices": [
{
"Variable": "$.iteratedItemsCount",
"NumericEquals": "$.totalItemsCount",
"Next": "CreateNotification"
}
],
"Default": "CreateReview"
},
"CreateReview": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-west-2:529627678433:function:CreateReview",
"Next": "CreateNotification",
"InputPath": "$",
"ResultPath": "$.CreateReviewResult",
"OutputPath": "$"
},
"CreateNotification": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-west-2:529627678433:function:CreateNotification",
"InputPath": "$",
"ResultPath": "$.CreateNotificationResult",
"OutputPath": "$",
"End": true
}
}
}
您还可以使用索引(当前索引和最后一个索引),而不是迭代的项数;它将帮助您跟踪您在何处创建评论。只是澄清一下,我们的目标是循环从getReviews检索到的评论,对吗?类似于
let reviews=getReviews();对于(评论中的评论){createReview(评论);sendNotification}
@ElFitz,是的,这是真的。我想在阶跃函数中循环。