Description
Is your feature request related to a problem? Please describe.
OK this might be a funny one to describe:
Currently we're using custom images, for SCF AWS Lambdas, and rely on the AWS SCF FunctionInvoker class (SCF 4.1.0 / SB 3.2.3) such that when we start the lambda we have
java ... com.amazonaws.services.lambda.runtime.api.client.AWSLambda org.springframework....FunctionInvoker
We're testing some of the features from this spring article including CDS and AOT. So far CDS has been fine but AOT is an issue for the following reasons:
- FunctionInvoker.start calls SpringApplication.run ...
- SpringApplication.deduceMainApplicationClass finds the main class in com.amazonaws.services.lambda.runtime.api.client.AWSLambda instead of the MAIN_CLASS for the function
- SpringApplication.addAotGeneratedInitializerIfNecessary then trys to resolve this class
String initializerClassName = "com.amazonaws.services.lambda.runtime.api.client.AWSLambda" + "__ApplicationContextInitializer";
- We finally get the message "You are starting the application with AOT mode enabled but AOT processing hasn't happened..."
Describe the solution you'd like
This needs thinking in case it's a breaking change but could we be opinionated in FunctionInvoker.start() to amend
SpringApplication.run(new Class[] {startClass, AWSCompanionAutoConfiguration.class}, properties)
to
new SpringApplicationBuilder().main(startClass).sources(new Class[] {startClass, AWSCompanionAutoConfiguration.class}).run(properties);
I think in this case the SpringApplication main class should not be deduced and instead set to the function start class.
If you think this makes sense I'm more than happy to provide a PR :-)
Describe alternatives you've considered
AOT does work fine if we use the CustomRuntimeEventLoop (and therefore remove com.amazonaws.services.lambda.runtime.api.client.AWSLambda from the path) however with this approach we cannot then use FUNCTION_INVOKER_LATE_INITIALIZATION which is important to us to stop AWS Init Timeout issues.