gpt4 book ai didi

amazon-web-services - 如何跨 aws 状态机重用状态定义?

转载 作者:行者123 更新时间:2023-12-05 07:38:01 24 4
gpt4 key购买 nike

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

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

状态机:

 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 ]

最佳答案

阿肖克,

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

希望这对您有所帮助!

关于amazon-web-services - 如何跨 aws 状态机重用状态定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48252289/

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