问题描述
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","subject": "some email subject","body": "some email body"
}
在查看状态函数的测试执行时,似乎 Setup Email
步骤没有成功地将 $.accounts
字符串插入 {{1} 的 accounts
数组输出} 步。相反,Analyze Report
步骤会看到以下输入:
Send Email
我尝试了设置等各种组合:
{
"recipients": "$.accounts","body": "some email body"
}
但它似乎不想插入。 AWS 提供的文档似乎有点缺乏这种方式。
TL;DR:如何使用 # (within the `Setup Email` step)
Result:
'recipients.$': '$.accounts'
类型的阶跃函数步骤有效地“重命名”输入参数(使用数组值)?
解决方法
您需要在 Parameters
状态下使用 Pass
。下面是一个例子:
{
"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" }
。