'SerializationException:Start of structure or map found where not expected: API Gateway to Step function
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.
Solution 1:[1]
Use escape character for your parameters as follows
{
"input": "{
\"my_params\": {
\"config\": \"config_value\"
}
}",
"name": "MyExecution",
"stateMachineArn": "my-arn"
}
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amit Dhara |
Solution 2 | Ampati Hareesh |