如何跨aws状态机重用状态定义?

时间:2018-01-14 17:34:50

标签: amazon-web-services aws-step-functions

我有一个像下面这样的状态机。如果有1000封要通知的消息,它会在15分钟内传播通知。

现在,如果我有一个具有完全相同状态流但具有自己的lambdas集的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 ]

1 个答案:

答案 0 :(得分:0)

阿肖克,

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

希望这有帮助!