3

我有一个像下面这样的状态机。如果它有 1000 条消息要通知,它会将通知分散到 15 分钟内。

现在,如果我有一个具有完全相同状态流但具有自己的一组 lambda 的 TwoHourStateMachine,我将如何重用这些状态,以便不再重复定义?

状态机:

 FifteenMinuteStateMachine:
 Type: "AWS::StepFunctions::StateMachine"
 Properties:
   StateMachineName: "FifteenMinuteStateMachine"
   DefinitionString:
     Fn::Sub: |-
       {
         "Comment": "A 15 minute state machine",
         "StartAt": "Initialize",
         "TimeoutSeconds": 900,
         "States": {
           "Initialize" : {
             "Type": "Task",
             "Resource": "${InitFifteenMinuteLambda.Arn}",
             "TimeoutSeconds": 15,
             "Retry": [ {
               "ErrorEquals": [ "States.Timeout", "Lambda.Unknown" ],
               "IntervalSeconds": 2,
               "MaxAttempts": 3,
               "BackoffRate": 2
             } ],
             "Catch": [{
               "ErrorEquals": ["States.ALL"],
               "ResultPath": "$.errorOutput",
               "Next": "Update Status"
             }],
             "Next": "Notification Job"
           },
           "Notification Job" : {
             "Type": "Task",
             "Resource": "${NotificationFifteenMinuteLambda.Arn}",
             "TimeoutSeconds": 15,
             "Retry": [ {
               "ErrorEquals": [ "States.Timeout", "Lambda.Unknown" ],
               "IntervalSeconds": 2,
               "MaxAttempts": 3,
               "BackoffRate": 2
             } ],
             "Catch": [{
               "ErrorEquals": ["States.ALL"],
               "ResultPath": "$.errorOutput",
               "Next": "Update Status"
             }],
             "Next": "All Notifications sent?"
           },
           "All Notifications sent?": {
             "Type": "Choice",
             "Choices": [
               {
                 "Variable": "$.status",
                 "StringEquals": "IN_PROGRESS",
                 "Next": "Wait X Seconds"
               },
               {
                 "Variable": "$.status",
                 "StringEquals": "SUCCEEDED",
                 "Next": "Update Status"
               }
             ],
             "Default": "Wait X Seconds"
           },
           "Wait X Seconds": {
             "Type": "Wait",
             "SecondsPath": "$.notificationIntervalInSeconds",
             "Next": "Notification Job"
           },
           "Update Status": {
             "Type": "Task",
             "Resource": "${StatusUpdateFifteenMinuteLambda.Arn}",
             "TimeoutSeconds": 15,
             "End": true
           }
         }
       }
   RoleArn: 
     Fn::GetAtt: [ StepFunctionExecutionRole, Arn ]
4

1 回答 1

0

阿肖克,

如果您可以使用一组 lambda 函数来解决问题,我相信在您的示例中已经为您完成了解决方案。您是否需要调用不同的 lambda 函数?理想情况下,您可以重用相同的 lambda 函数并在定义中重用它。不幸的是,您目前不能在运行时使用 ARN 变量,我相信这是您所要求的。

希望这可以帮助!

于 2018-02-02T21:50:00.670 回答