Resolved this problem by switching the lambda handler function to use Stream rather than attempting to serialize/deserialize JSON into POJOs. When using the API Gateway Lambda Proxy the input to handler is a complicated JSON structure that I didn't want to try and replicate as a Java/Scala class. It was easier to process the input as a stream, parse it into a JsonObject, and then convert the body of the message into my POJO using Gson or equivalent library. Sample handler below, you can also see a larger example hereclass CancellationHandler { def cancelAppointment(request: InputStream, response: OutputStream, context: Context): Unit = { val logger = context.getLogger val parser: JsonParser = new JsonParser var inputObj: JsonObject = null val gson: Gson = new Gson try { inputObj = parser.parse(IOUtils.toString(request, "UTF-8")).getAsJsonObject } catch { case e: IOException => logger.log("Error while reading request\n" + e.getMessage) throw new RuntimeException(e.getMessage) } val body: String = inputObj.get("body").getAsString val appointment: Appointment = gson.fromJson(body, classOf[Appointment]) val apiGatewayProxyResponse = new ApiGatewayProxyResponse val cancelResponse = new CancelResponse cancelResponse.setMessage("Cancelled appointment with id " + appointment.getAppointmentId) apiGatewayProxyResponse.setBody(gson.toJson(cancelResponse)) apiGatewayProxyResponse.setStatusCode("200") val headerValues = new util.HashMap[String, String] headerValues put("Content-Type", "application/json") apiGatewayProxyResponse.setHeaders(headerValues) val output: String = gson.toJson(apiGatewayProxyResponse) IOUtils.write(output, response, "UTF-8") }}推荐答案 Lambda代理的输入形状将不同于常规的非代理Lambda集成的形状.当然,这对于您的用例很重要,因为您使用的是Java/Scala,因此必须显式构造输入POJO.The input shape for the Lambda proxy will be different than the shape for the regular non-proxy Lambda integration. This is important for your use case of course because you're using Java/Scala where you have to explicitly structure the input POJO.这是代理输入的样子:{ "resource": "\/pets", "path": "\/pets", "httpMethod": "POST", "headers": null, "queryStringParameters": null, "pathParameters": null, "stageVariables": null, "requestContext": { ... "stage": "test-invoke-stage", "requestId": "test-invoke-request", "identity": { ... }, "resourcePath": "\/pets", "httpMethod": "POST" }, "body": "{\n \"foo\":\"bar\"\n}", <---- here's what you're looking for "isBase64Encoded": false}文档: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html 这篇关于HTTP请求正文未通过AWS API Gateway进入AWS Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-06 18:57