有一个 API 网关使用 lambda 代理调用 lambda 函数。
记录以下工作正常的身体并将身体发回:
package com.dapper.cloud.function;
import java.util.Map;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
public class GrantJwt implements RequestHandler<Map<String, Object>, APIGatewayProxyResponseEvent>{
@Override
public APIGatewayProxyResponseEvent handleRequest(Map<String, Object> input, Context context){
System.out.println(input.get("body").toString());
return new APIGatewayProxyResponseEvent().withStatusCode(200).withBody(input.get("body").toString());
}
}
当我更新它以使用ObjectMapper这样的方式时:
package com.dapper.cloud.function;
import java.util.Map;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.fasterxml.jackson.databind.ObjectMapper;
public class GrantJwt implements RequestHandler<Map<String, Object>, APIGatewayProxyResponseEvent>{
@Override
public APIGatewayProxyResponseEvent handleRequest(Map<String, Object> input, Context context){
ObjectMapper m = new ObjectMapper();
System.out.println(input.get("body").toString());
return new APIGatewayProxyResponseEvent().withStatusCode(200).withBody(input.get("body").toString());
}
}
日志不显示正文,响应是:
{
"message": "Internal server error"
}
我可以在 AWS Lambda 中使用 Jackson 吗?
父POM
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.0</version>
</dependency>
温温酱
相关分类