AWS Step Functions:如何使用 Pass 步骤 "rename" 输入参数
AWS Step Functions : How to "rename" an input parameter using a Pass step
我有一个状态机,其中包含以下相关状态:
States:
'Analyze Report':
Type: Task
Resource: 'arn:aws:states:::lambda:invoke'
Parameters:
FunctionName: '(redacted)'
OutputPath: '$.Payload'
Next: 'Setup Email'
'Setup Email':
Type: Pass
Result:
recipients: '$.accounts'
subject: 'some email subject'
body: 'some email body'
ResultPath: '$'
Next: 'Send Email'
'Send Email':
Type: Task
Resource: 'arn:aws:states:::lambda:invoke'
Parameters:
FunctionName: '(redacted)'
OutputPath: '$.Payload'
Next: '(some downstream task)'
与 Analyze Report
步骤关联的 lambda 函数的输出格式为:
{
"accounts": ["foo", "bar", "baz"],
"error_message": null,
"success": true
}
与 Send Email
步骤关联的 lambda 函数需要以下形式的输入:
{
"recipients": ["foo", "bar", "baz"],
"subject": "some email subject",
"body": "some email body"
}
查看状态函数的测试执行时,似乎 Setup Email
步骤未成功将 $.accounts
字符串插入 accounts
数组输出 Analyze Report
步骤。相反,Send Email
步骤会看到以下输入:
{
"recipients": "$.accounts",
"subject": "some email subject",
"body": "some email body"
}
我尝试了各种组合,例如设置:
# (within the `Setup Email` step)
Result:
'recipients.$': '$.accounts'
但它似乎不想插值。 AWS提供的文档在这方面似乎有点欠缺
TL;DR: 如何使用 Pass
类型的阶跃函数步骤有效地“重命名”输入参数(使用数组值)?
您需要在 Pass
状态下使用 Parameters
。这是一个例子:
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Pass",
"Parameters": {
"newName.$": "$.oldName"
},
"Next": "World"
},
"World": {
"Type": "Pass",
"Result": "World",
"End": true
}
}
}
当我运行上面的负载为{ "oldName": "some value" }
时,第二个状态的输入是{ "newName": "some value" }
。
我有一个状态机,其中包含以下相关状态:
States:
'Analyze Report':
Type: Task
Resource: 'arn:aws:states:::lambda:invoke'
Parameters:
FunctionName: '(redacted)'
OutputPath: '$.Payload'
Next: 'Setup Email'
'Setup Email':
Type: Pass
Result:
recipients: '$.accounts'
subject: 'some email subject'
body: 'some email body'
ResultPath: '$'
Next: 'Send Email'
'Send Email':
Type: Task
Resource: 'arn:aws:states:::lambda:invoke'
Parameters:
FunctionName: '(redacted)'
OutputPath: '$.Payload'
Next: '(some downstream task)'
与 Analyze Report
步骤关联的 lambda 函数的输出格式为:
{
"accounts": ["foo", "bar", "baz"],
"error_message": null,
"success": true
}
与 Send Email
步骤关联的 lambda 函数需要以下形式的输入:
{
"recipients": ["foo", "bar", "baz"],
"subject": "some email subject",
"body": "some email body"
}
查看状态函数的测试执行时,似乎 Setup Email
步骤未成功将 $.accounts
字符串插入 accounts
数组输出 Analyze Report
步骤。相反,Send Email
步骤会看到以下输入:
{
"recipients": "$.accounts",
"subject": "some email subject",
"body": "some email body"
}
我尝试了各种组合,例如设置:
# (within the `Setup Email` step)
Result:
'recipients.$': '$.accounts'
但它似乎不想插值。 AWS提供的文档在这方面似乎有点欠缺
TL;DR: 如何使用 Pass
类型的阶跃函数步骤有效地“重命名”输入参数(使用数组值)?
您需要在 Pass
状态下使用 Parameters
。这是一个例子:
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Pass",
"Parameters": {
"newName.$": "$.oldName"
},
"Next": "World"
},
"World": {
"Type": "Pass",
"Result": "World",
"End": true
}
}
}
当我运行上面的负载为{ "oldName": "some value" }
时,第二个状态的输入是{ "newName": "some value" }
。