我有一个在SpringBoot中开发并部署了AWS Environment的应用程序。当我尝试通过Configure Test Events在AWS Lambda Console上测试AWS Lambda Function时遇到以下错误。在检查CloudWatch Logs时,存在与db相关的UnknownHostException。但是,在构建期间,所有测试用例都可以正常工作,并在环境中填充db。但是,这从Lambda Console运行时不起作用,并引发错误。
{
"statusCode": 502,
"multiValueHeaders": {
"Content-Type": [
"application/json"
]
},
"body": "{\"message\":\"Gateway timeout\"}",
"base64Encoded": false
}
登录Cloud Watch
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:114) [LambdaJavaRTEntry-1.0.jar:?]
java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48)
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174)
这是我的LambdaHandler代码,
public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> {
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(SpringBootApplication.class);
} catch (ContainerInitializationException e) {
// if we fail here. We re-throw the exception to force another cold start
e.printStackTrace();
throw new RuntimeException("Could not initialize Spring Boot Application", e);
}
}
@Override
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) {
return handler.proxy(awsProxyRequest, context);
}
}
这是Application类的代码
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
}
}