简体   繁体   中英

Use JSON Input to Replace 'Variable' in AWS Step Function

I have an AWS Step Function, which I would like to pass a value to via the JSON input included when starting the execution. The Step function starts an ETL job and checks it's status via calling Lambda Functions that perform said tasks. The StartGlueJob Lambda function is initiated via a JobName JSON input. The value I would like to pass in is an argument for the glue job named 'regionalCenters' where the desired value would be 'LA' in this case.

I have attemped, as seen below, to use the $.value syntax to pass from the JSON input but this is not functioning as intended and I am not sure why.

Snippet of Lambda Code:

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

JSON input

{
    "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
    }
  }
}

You missed.$ in the end regionalCenters

It should be "arguments": {"regionalCenters.$": "$.value"}

see here https://docs.aws.amazon.com/step-functions/latest/dg/connect-parameters.html

I was able to solve to my own problem by changing up the Result and adding a ResultPath, a la:

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

Changing the Result allowed me to add the string to the.jobName node via the ResultPath, while appending the input of {"value": "LA"} to the Output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM