【问题标题】:AWS Step Functions : How to "rename" an input parameter using a Pass stepAWS Step Functions:如何使用 Pass 步骤“重命名”输入参数
【发布时间】:2021-08-02 22:16:05
【问题描述】:

我有一个包含以下相关状态的状态机:

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 字符串插入到来自 Analyze Report 步骤的 accounts 数组输出中。相反,Send Email 步骤会看到以下输入:

{
  "recipients": "$.accounts",
  "subject": "some email subject",
  "body": "some email body"
}

我尝试了各种组合,例如设置:

# (within the `Setup Email` step)
Result:
  'recipients.$': '$.accounts'

但它似乎不想插值。 AWS 提供的文档在这种方式上似乎有点欠缺。

TL;DR:如何使用Pass 类型的步进函数步骤有效地“重命名”输入参数(带有数组值)?

【问题讨论】:

标签: aws-lambda aws-step-functions


【解决方案1】:

您需要在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" }

【讨论】:

  • 谢谢!我自己偶然发现了这个并且正要回答,所以我可以验证它是否有效!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-05
  • 2022-11-08
  • 2018-05-18
相关资源
最近更新 更多