hat*_*lla 12 amazon-web-services aws-step-functions
是否可以有以下类型的阶跃函数图,即来自 2 个并行状态输出,一个组合状态:
如果是,那么 json 会是什么样子?如果不是,为什么?
并行任务总是输出一个数组(每个分支包含一个条目)。
您可以"ResultPath": "$.ParallelOut"在并行状态定义中告诉 AWS 步骤函数将输出附加到原始输入中的新(或现有)属性中,但这似乎不是您想要实现的目标。
要合并并行任务的输出,您可以利用"Type": "Pass"状态来定义要应用于 JSON 文档的转换。
例如,在下面的状态机中,我正在转换一个 JSON 数组...
[
{
"One": 1,
"Two": 2
},
{
"Foo": "Bar",
"Hello": "World"
}
]
Run Code Online (Sandbox Code Playgroud)
...进入一些属性
{
"Hello": "World",
"One": 1,
"Foo": "Bar",
"Two": 2
}
Run Code Online (Sandbox Code Playgroud)
{
"Comment": "How to convert an array into properties",
"StartAt": "warm-up",
"States": {
"warm-up": {
"Type": "Parallel",
"Next": "array-to-properties",
"Branches": [
{
"StartAt": "numbers",
"States": {
"numbers": {
"Type": "Pass",
"Result": {
"One": 1,
"Two" : 2
},
"End": true
}
}
},
{
"StartAt": "words",
"States": {
"words": {
"Type": "Pass",
"Result": {
"Foo": "Bar",
"Hello": "World"
},
"End": true
}
}
}
]
},
"array-to-properties": {
"Type": "Pass",
"Parameters": {
"One.$": "$[0].One",
"Two.$": "$[0].Two",
"Foo.$": "$[1].Foo",
"Hello.$": "$[1].Hello"
},
"End": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
有可能如下图所示
并行状态应该是这样的
"MyParallelState": {
"Type": "Parallel",
"InputPath": "$",
"OutputPath": "$",
"ResultPath": "$.ParallelResultPath",
"Next": "SetCartCompleteStatusState",
"Branches": [
{
"StartAt": "UpdateMonthlyUsageState",
"States": {
"UpdateMonthlyUsageState": {
"Type": "Task",
"InputPath": "$",
"OutputPath": "$",
"ResultPath": "$.UpdateMonthlyUsageResultPath",
"Resource": "LambdaARN",
"End": true
}
}
},
{
"StartAt": "QueueTaxInvoiceState",
"States": {
"QueueTaxInvoiceState": {
"Type": "Task",
"InputPath": "$",
"OutputPath": "$",
"ResultPath": "$.QueueTaxInvoiceResultPath",
"Resource": "LambdaARN",
"End": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
的输出MyParallelState将按数组填充,来自Parallel state. 它们填充在ParallelResultPath对象中并将被传递到下一个状态
{
"ParallelResultPath": [
{
"UpdateMonthlyUsageResultPath": Some Output
},
{
"QueueTaxInvoiceResultPath": Some Output
}
]
}
Run Code Online (Sandbox Code Playgroud)
您的图表在技术上是错误的,因为没有状态可以为其Next任务设置多个状态。您无法StartAt通过提供多个状态名称来启动状态机。另外,即使有可能,我也看不出为什么要运行两个并行状态,而不是运行一个并行状态,并将所有子状态分成两个。
| 归档时间: |
|
| 查看次数: |
9654 次 |
| 最近记录: |