有一个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>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9</version>
</dependency>
</dependencies>
儿童建物
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 0 :(得分:0)
愚蠢,但是如果这可以帮助任何人,我会很高兴。
ObjectMapper不是问题。我使用travis-ci进行了几次部署,显然,如果未设置memory_size和timeout,则默认情况下会发生这种情况,默认使用128 mb且使用3秒。这与新的lambda的默认值(512 mb and 15秒)不同。
我在travis论坛上提出了更改此要求的请求。