Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Make Spring AOT play nice when using AWS FunctionInvoker #1113

Closed
davidmelia opened this issue Feb 23, 2024 · 5 comments
Closed
Milestone

Comments

@davidmelia
Copy link
Contributor

davidmelia commented Feb 23, 2024

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.

@davidmelia
Copy link
Contributor Author

FYI I've tested this by copying FunctionInvoker and adding the above change - Spring AOT works great :-)

davidmelia added a commit to davidmelia/spring-cloud-function that referenced this issue Feb 29, 2024
@davidmelia
Copy link
Contributor Author

#1119

@davidmelia
Copy link
Contributor Author

davidmelia commented Mar 19, 2024

@olegz - would it be possible to review my PR? I believe there is a spring cloud release 26/03/2024 so it would be great to target this if you agree with the PR. The change itself is simple but depends if it has implications elsewhere??

@olegz
Copy link
Contributor

olegz commented Mar 27, 2024

Yes, sorry, will review shortly

@olegz olegz added this to the 4.1.2 milestone Mar 27, 2024
olegz added a commit that referenced this issue Mar 28, 2024
@olegz olegz closed this as completed Mar 28, 2024
@olegz
Copy link
Contributor

olegz commented Mar 28, 2024

Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants