summerNight
summerNight

Reputation: 1496

Render a variable from input JSON into Step Function non-path supported variable

I am trying to make the following spec work for setting up a Dataset Import. I am passing in an input JSON as shown below. The keys with .$ JSONPath support are able to read the values from the input JSON.

However, I am unable to pass in a value from the input JSON into S3 object which does not seem to support the Path.$, and Path itself does not render the JSONPath structure.

How do I populate Path within the S3Config to read from the input JSON?

"Import-Forecast-Dataset": {
      "Type": "Task",
      "Parameters": {
        "DatasetImportJobName.$": "$.ProjectName",
        "DatasetArn.$": "$.createDatasetResult.DatasetArn",
        "DataSource": {
          "S3Config": {
            "Path": "$.S3Path",
            "RoleArn": "arn:aws:iam::XXXXXXXXXXXXX"
          }
        },
        "TimestampFormat": "yyyy-MM-dd"
      },
      "Resource": "arn:aws:states:::aws-sdk:forecast:createDatasetImportJob",
      "Next": "Create-DatasetGroup",
      "ResultPath": "$.createDatasetImportJobResult"
    }

input JSON:

{
"ProjectName": "A",
"S3Path": "s3://somepath"
}

Upvotes: 0

Views: 1227

Answers (1)

Brett Ryan
Brett Ryan

Reputation: 28255

You just need to append the .$ suffix to the Path attribute.

"Path.$": "$.S3Path",

If this is not the StartAt step within your state machine, it's possible that the input to the step is not including the S3Path. If this is the case, you can use the context object to get the input parameters to the function instead.

"Path.$": "$$.Execution.Input.database",

I can verify creating a single step step function with the following, once executed does in fact pass the formed parameters correctly to the resource:

{
  "End": true,
  "Parameters": {
    "DataSource": {
      "S3Config": {
        "Path.$": "$$.Execution.Input.S3Path",
        "RoleArn": "arn:xxx:iam::000000000000:role/xxxx"
      }
    },
    "DatasetArn.$": "$$.Execution.Input.DatasetArn",
    "DatasetImportJobName.$": "$$.Execution.Input.ProjectName",
    "TimestampFormat": "yyyy-MM-dd"
  },
  "Resource": "arn:aws:states:::aws-sdk:forecast:createDatasetImportJob",
  "Type": "Task"
}

I then executed this with the following input:

{
  "ProjectName":"XXXX",
  "DatasetArn":"arn:xxx:forecast:::test",
  "S3Path":"s3://dummy/prefix"
}

And verified in the execution console that this was the input passed to the step:

{
  "DataSource": {
    "S3Config": {
      "RoleArn": "arn:xxx:iam::000000000000:role/xxxx",
      "Path": "s3://dummy/prefix"
    }
  },
  "TimestampFormat": "yyyy-MM-dd",
  "DatasetArn": "arn:xxx:forecast:::test",
  "DatasetImportJobName": "XXXX"
}

Upvotes: 0

Related Questions