Could not parse request body into json: Unexpected character (\'-\' (code 45)) AWS Lambda + API + Postman

前端 未结 3 1580
青春惊慌失措
青春惊慌失措 2021-01-03 23:50

I have been trying for a few days to get a parameter sent from the API Gateway in AWS to a Lambda function and I am having no success.

I decided to start from the b

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 00:42

    Read the error message very carefully, it actually tells you the problem. For example, I got

    Could not parse request body into json: Unexpected character (\'\"\' (code 34)): was expecting comma to separate Object entries

    So the problem is that I'm missing a comma. I check my Lambda's Integration Request - Body Mapping Template:

    {
    "age" : $input.json('$.persondata.age'),
    "income" : $input.json('$.persondata.income')
    "height" : $input.json('$.persondata.height')
    }
    

    Can you spot the problem? I am missing a comma after the income line.


    Here is another example.

    Could not parse request body into json: Unexpected character (\'}\' (code 125)): expected a value

    When I look at the Integration Request - Body Mapping Template:

    #set($inputRoot = $input.path('$'))
    {
      "age" : $inputRoot.age,
      "height" : $inputRoot.height,
      "income" : $inputRootincome
    }
    

    Can you spot the problem? I am missing a dot in $inputRootincome.

提交回复
热议问题