我有一个Spring Boot 应用程序,我试图部署在AWS lambda。
我添加了StreamLambdaHandler作为处理程序类
公共类StreamLambda处理程序实现请求流处理程序{
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 ms超时内初始化框架
因此我更新了lambda配置,将超时设置为5分钟,并在StreamLambdaHandler类的静态块中添加了以下行:LambdaContainerHandler.getContainerConfig().setInitializationTimeout(2000000);
现在,我在线程“Thread-0”java.lang.IllegalArgumentException中看到下面的异常异常:无法找到计时器SPRINGBOOT2_COLD_START
有人能给我指出正确的方向吗?因为我在AWS服务和lambda方面是个新手
1条答案
按热度按时间zy1mlcev1#
在 StreamLambdaHandler 方法中注解掉以下代码后,我没有看到此错误