16

I am using the standard blog tutorial on integrating api gateway with step functions from here: https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-api-gateway.html

My step function expects the following output:

{
  "my_params": {
     "config": "config_value"
  }
}

the Request body needed to do a post request as mentioned in the blog is:

{
 "input": "{}",
   "name": "MyExecution",
   "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:HelloWorld"
}

I am passing my required input like this:

{
 "input": {
           "my_params": {
             "config": "config_value"
             }
          },
  "name": "MyExecution",
  "stateMachineArn": "my-arn"
}

However, I am continuously getting following error:

{
"__type": "com.amazon.coral.service#SerializationException",
  "Message": "Start of structure or map found where not expected."
}

Can someone tell me what exactly is the problem here? What am I doing wrong here? Quick help appreciated.

2
  • 1
    I'm experiencing something similar but I don't know the exact solution. My best guess is that the value of "input" is supposed to be a string (notice the blog says "input": "{}" rather than "input": {}. Try converting your input value to a string and passing that in instead of your map object.
    – cody
    Feb 13, 2018 at 4:19
  • 1
    @cody I actually found out the solution for that. sorry, couldnt post it before. Yes, you are correct. It needs the input in a stringified manner. I used JSON.stringify to create a string out of JSON... then used it to trigger the API and it worked.
    – Omkar
    Feb 13, 2018 at 4:27

4 Answers 4

22

Use escape character for your parameters as follows

{
 "input": "{
           \"my_params\": {
             \"config\": \"config_value\"
             }
          }",
  "name": "MyExecution",
  "stateMachineArn": "my-arn"
}
3
  • 1
    Thank you very much, I spent a bunch of time looking for this info in AWS docs!
    – DrCord
    Nov 20, 2020 at 23:33
  • 2
    Something to note is that the Mapping Templates don't like line breaks in your value, so I had to combine all of my escaped JSON into a single line.
    – Sators
    Mar 23, 2021 at 13:55
  • I wanted to add that you can use $util Variables to escape any input json acocrdingly. Jan 6, 2023 at 19:27
1

To pass json object as input to a step function through appSync.

Two Steps:

  1. From client code, pass input : JSON.stringify(jsonObject)
  2. In the resolver, resolve "input":"$util.escapeJavaScript($ctx.args.input).replaceAll("\\'","'")"
1

I had this error log when I was making this simple mistake:

//Have a value in a JSON object
const temp = {
    id: "val",
}

//Accidentally trying to store a map in a string
const data = {
     id: {S: temp} 
}

//Referencing the right field fixed it
const data = {
     id: {S: temp.id} 
}
-1

For the people who faced below issue, when trying to set Data with JSON payload (from console )

Convert the JSON payload to base64 string

Request body e.g

 {
       "Data":  { 
          "name": "Dean",
          "role": "actor"
        },
       "StreamName": "yourstream",
       "Partitionkey": "youPartitionKey"
       }
       }

Error

{
  "__type": "SerializationException",
  "Message": "Start of structure or map found where not expected."
}

Go to Method Execution Panel -> Integration Request(AWS) -> Mapping Templates -> Request body passthrough

Now add template, write the code in the template to convert the JSON payload of the Data key to base64 string

{
    "Data": "$util.base64Encode($input.json('$.Data'))",
....
}

Hope this helps!!! Thanks

2
  • this doesn't work. ` Validation Result: warnings : [], errors : [Invalid content type specified: { "Data": "$util.base64Encode($input.json('$.Data'))", .... }] ` Jun 18, 2021 at 19:13
  • @ChumiestBucket can you share your input, the above was written for this error Convert the JSON payload to base64 string, please check the latest docs, as it was written two years ago, also share the link here if possible Jun 22, 2021 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.