SerializationException:Start 在预期之外的地方找到了结构或地图:API Step 函数的网关

SerializationException:Start of structure or map found where not expected: API Gateway to Step function

我正在使用标准博客教程将 api 网关与此处的步骤函数集成: https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-api-gateway.html

我的步骤函数需要以下输出:

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

博客中提到的 post 请求所需的请求主体是:

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

我正在像这样传递我需要的输入:

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

但是,我不断收到以下错误:

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

有人能告诉我这里的问题到底是什么吗?我在这里做错了什么?感谢快速帮助。

按如下方式为您的参数使用转义字符

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

对于遇到以下问题的人,当尝试使用 JSON 有效负载(来自控制台)设置数据时

Convert the JSON payload to base64 string

请求正文例如

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

错误

{
  "__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

现在添加模板, 在模板中编写代码,将 Data key 的 JSON payload 转换为 base64 string

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

希望对您有所帮助!!! 谢谢