使用JSON输入替换AWS Step Function中的'Variable'

时间:2019-04-30 01:37:02

标签: aws-lambda aws-step-functions

我有一个AWS Step Function,我想通过开始执行时包含的JSON输入将值传递给。 Step函数启动ETL作业,并通过调用执行上述任务的Lambda函数来检查其状态。 StartGlueJob Lambda函数通过JobName JSON输入启动。我要传递的值是名为“ regionalCenters”的胶粘作业的一个参数,在这种情况下,所需的值为“ LA”。

如下所示,我试图使用$ .value语法从JSON输入中传递消息,但这不能按预期运行,我不确定为什么。

Lambda代码段:

let jobInfo = await glue.startJobRun({ JobName: jobName, Arguments: arguments }).promise();

JSON输入

{
    "value": "LA"
}

Step Function

{
  "StartAt": "InitStartEtl",
  "States": {
    "InitStartEtl": {
      "Type": "Pass",
      "Result": {
        "jobName": "name-of-my-etl-job",
        "arguments": {"regionalCenters": "$.value"}
      }
    },
    "StartEtl": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:<redacted>",
      "Next": "WaitForForEtlCheck"
    },
    "WaitForForEtlCheck": {
      "Type": "Wait",
      "Seconds": 10,
      "Next": "GetEtlState"
    },
    "GetEtlState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:<redacted>",
      "Next": "IsEtlFinished"
    },
    "IsEtlFinished": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.state",
          "StringEquals": "READY",
          "Next": "EtlDone"
        }
      ],
      "Default": "WaitForForEtlCheck"
    },
    "EtlDone": {
      "Type": "Pass",
      "End": true
    }
  }
}

2 个答案:

答案 0 :(得分:2)

您错过了末尾地区中心的。$

应该是         “ arguments”:{“ regionalCenters。$”:“ $ .value”}

请参阅此处 https://docs.aws.amazon.com/step-functions/latest/dg/connect-parameters.html

答案 1 :(得分:0)

我可以通过更改Result并添加一个ResultPath来解决自己的问题:

{
  "StartAt": "InitStartEtl",
  "States": {
    "InitStartEtl": {
      "Type": "Pass",
      "Result": "name-of-my-etl-job",
      "ResultPath": "$.jobName",
      "Next": "StartEtl"
    },

更改结果使我可以通过ResultPath将字符串添加到.jobName节点,同时将{“ value”:“ LA”}的输入附加到输出