Search code examples
arraysamazon-web-serviceslistaws-step-functions

Passing custom variable to a list parameter in stepfunctions?


I am trying to make a call to StartTranslationTask, and it takes a parameter for target languagecodes in form of a list

aw

However, the following fails as it is passed as a literal string

"TargetLanguageCodes": ["$.language"]

1 validation error detected: Value '[$.language]' at 'targetLanguageCodes' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 5, Member must have length greater than or equal to 2, Member must not be null] (Service: Translate, Status Code: 400, Request ID: 30d4a91f-5bdf-4302-aae8-9f8355816229)

If I try to pass it as a list it fails validation since it is passing a list encoded as a string

"TargetLanguageCodes": "$.language"

What are my options here? Seems like it should be so easy? This is the input tot the translation task

{
  "language": "de",
  "bucket": "mybucket",
  "job_name": "mytranslationjob--2023-07-08-00-42-21-507725"
}

Solution

  • Add a .$ suffix to the key to indicate to Step Functions that the value contains a path substitution. Convert the value to an array with the States.Array intrinsic function:

    "TargetLanguageCodes.$": "States.Array($.language)"