![](/img/trans.png)
[英]AWS Java Lambda Function with API Gateway - POJO input and OutputStream output
[英]AWS Gateway calling AWS Lambda Java Function receives null body
我正在使用 aws-lambda-java-events 庫在 java 中實現 aws lambda function 編碼。 出於故障排除的目的,我現在只是嘗試使用相同的請求正文進行響應
public class LambdaFunctionHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
return new APIGatewayProxyResponseEvent().withBody(input.getBody());
}
}
我已經定義了上述 lambda function 和一個 api 網關,但我得到input.getBody
為 Z20B9A6259CC48DDAE DDAE The output of the lambda function is an empty json object
{}
我通過 AWS lambda 測試控制台對此進行了測試。 執行成功,output如上。 api 網關集成請求配置為在 POST 方法上調用上述 lambda function。
以下是我的查詢
APIGatewayProxyRequestEvent getBody()
字符串的一部分?APIGatewayProxyRequestEvent getBody()
字符串變量中的 API 網關 POST 方法? 我需要定義映射模板嗎? 如果是這樣,它應該是什么樣子(我多次嘗試但沒有成功)我想通過 POSTMAN 傳遞給 API 網關 POST 方法的請求正文是
{
"question":"Hello, how are you doing?"
}
謝謝!
我也試過了。 我使用的代碼是
public class LambdaFunctionHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent,
Context context) {
return new APIGatewayProxyResponseEvent().withBody(apiGatewayProxyRequestEvent.getBody());
}
}
我猜您是直接從 AWS 控制台進行測試的。 您不能直接測試事件觸發的 lambda。
您必須使用“Amazon API 網關代理”事件創建測試,如下所示。
並將請求正文作為參數的一部分傳遞。
通過這些輸入,我得到了預期的 output。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.