Search code examples
jsonamazon-web-servicesjsonpathaws-step-functions

Reference value from state’s input, using JSONPath syntax in combination with a hard-coded string


Im creating a SSM document with a state machine, in the api parameter: Name.

I want to combine a value from the state’s input (InstanceID) with the hard-coded text EC2-PROD-WEBSRV-CP_RAM_SWAP-Document.

Im wondering if something like "key2.$": "$.inputValue[+hardcodedstring]" is possible.

So the final value will be i-013165f64447e25e0-EC2-PROD-WEBSRV-CP_RAM_SWAP-Document.

SSM CreateDocument schema:

{
   "Attachments": [ 
      { 
         "Key": "string",
         "Name": "string",
         "Values": [ "string" ]
      }
   ],
   "Content": "string",
   "DisplayName": "string",
   "DocumentFormat": "string",
   "DocumentType": "string",
   "Name": "string",
   "Requires": [ 
      { 
         "Name": "string",
         "Version": "string"
      }
   ],
   "Tags": [ 
      { 
         "Key": "string",
         "Value": "string"
      }
   ],
   "TargetType": "string",
   "VersionName": "string"
}

I read the documentation but It seems it is possible just one or the other option.

https://aws.amazon.com/blogs/compute/using-jsonpath-effectively-in-aws-step-functions/


Solution

  • Use the States.Format intrinsic function to interpolate the value into a string:

    "key2.$": "States.Format('{}-EC2-PROD-WEBSRV-CP_RAM_SWAP-Document', $.inputValue)"