【发布时间】:2022-12-25 12:29:54
【问题描述】:
我有一个 spring boot 应用程序,我试图在 AWS lambda 上部署它。
我将 StreamLambdaHandler 添加为处理程序类
公共类 StreamLambdaHandler 实现 RequestStreamHandler {
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
//handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(SituationalFlexibilityApp.class);
// For applications that take longer than 10 seconds to start, use the async builder:
handler = new SpringBootProxyHandlerBuilder<AwsProxyRequest>()
.defaultProxy()
.asyncInit()
.springBootApplication(SituationalFlexibilityApp.class)
.buildAndInitialize();
// we use the onStartup method of the handler to register our custom filter
handler.onStartup(servletContext -> {
FilterRegistration.Dynamic registration = servletContext.addFilter("CognitoIdentityFilter",CognitoIdentityFilter.class);
registration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
});
} 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);
}
}
public StreamLambdaHandler() {
Timer.enable();
}
/*
* public StreamLambdaHandler() throws ContainerInitializationException {
*
* handler = new SpringBootProxyHandlerBuilder() .defaultProxy() .asyncInit()
* .springBootApplication(SlowApplication.class) .buildAndInitialize(); }
*/
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
handler.proxyStream(input, output, context);
}
当我在 AWS lambda 上测试它时,我得到以下异常 com.amazonaws.serverless.exceptions.ContainerInitializationException:无法在 20000 毫秒超时内初始化框架
所以我更新了 lambda 配置,超时时间为 5 分钟,并在 StreamLambdaHandler 类的静态块中添加了以下行 LambdaContainerHandler.getContainerConfig().setInitializationTimeout(2000000);
现在,我看到以下异常 线程“Thread-0”中的异常 java.lang.IllegalArgumentException:找不到计时器 SPRINGBOOT2_COLD_START
有人能给我指出正确的方向吗,因为我是 AWS 服务和 lambda 的菜鸟
【问题讨论】:
-
这个问题解决了吗?我看到了同样的问题
标签: spring amazon-web-services aws-lambda timeout