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

[RFC] Support for native-image compilation #335

Closed
sapessi opened this issue Apr 9, 2020 · 8 comments
Closed

[RFC] Support for native-image compilation #335

sapessi opened this issue Apr 9, 2020 · 8 comments

Comments

@sapessi
Copy link
Collaborator

sapessi commented Apr 9, 2020

  • Implementations: Spring 5.3.x / Spring Boot 2

Scenario

As the Spring framework adds support for GraalVM's native image tool, we should explore making it easy to compile SpringBoot applications and execute them as a custom runtime in AWS Lambda

This issue serves as a tracker for this project to make design decisions and collect feedback on the implementation

@urmichm
Copy link

urmichm commented Dec 4, 2022

Totally support this issue!
@sapessi if you are interested I might help to create a project for GraalVM and Springboot with MVC controllers.

@deki
Copy link
Collaborator

deki commented Dec 5, 2022

Please check https://catalog.workshops.aws/java-on-aws-lambda/en-US/01-migration/03-alternatives/graalvm for an example. Will get that added to the docs.

@fsomme2s
Copy link

fsomme2s commented Jun 9, 2023

Now that we have Spring Boot 3 Support (see #487, which I tested and it works really nice so far! Awesome work!), maybe it's time to revive this issue?

I can use Spring Boot Native to create Custom Images; I can use the serverless-java-container lib to "bridge" Api Gateway Events into Spring ... But I can't get my head around how to combine these two.

Is this already possible? Or would it need some kind of special Custom Runtime "Event Loop" thing, similar to this ? (That would call SpringBootLambdaContainerHandler.proxy(...) when it polls a new event)

@lenis0012
Copy link

lenis0012 commented Jun 27, 2023

@fsomme2s One critical difference between native image support for spring via "Spring Cloud Function" and aws-serverless-java-container is the runtime.

You can use spring boot 3 to compile to a native image, create a custom runtime and use that to make a simple function with the code already provided by Spring Cloud Function. But this will not correctly proxy API Gateway requests.

The reason why aws-serverless-container does not work out of the box is that it assumes to be running in a java runtime. When this happens, the invocation is handled by the AWS Platform which executes a java method somewhere. This does not work with a custom runtime where you have to listen for invocations by calling out to an API.

The SAM template in the spring boot 3 example uses the following for runtime invocation:

Handler: com.amazonaws.serverless.sample.springboot3.StreamLambdaHandler::handleRequest

From my understanding, this is the part that has to be changed.

What does work is the custom runtime integration that is provided by Spring Cloud Function's AWS adapter. (spring-cloud-starter-function-adapter-aws). Similar logic would have to be integrated into this project to make it work with native compilation. And a different SAM template is required that specifies a custom runtime. I might be missing something but from my understanding that's what has to happen.

I don't think it would be too difficult to create a runtime inializer inspired by CustomRuntimeInitializer and CustomRuntimeEventLoop.

However, it seems that it is quite possible Spring Cloud Function already supports this since very recently. I haven't confirmed but there is https://github.com/spring-cloud/spring-cloud-function/blob/main/spring-cloud-function-adapters/spring-cloud-function-adapter-aws-web/src/main/java/org/springframework/cloud/function/adapter/aws/web/WebProxyInvoker.java

@babaksd
Copy link

babaksd commented Jan 4, 2024

@deki I'm having trouble integrating aws-serverless-java-container-springboot3 with Graalvm and a custom lambda runtime/handler. Has anyone successfully managed to do this? Is the anyway to make it work?

@deki
Copy link
Collaborator

deki commented Jan 5, 2024

Hey @babaksd, we are aware. @olegz is currently working on that and we'll include it in the next release (current plan is to have that end of this month).

@babaksd
Copy link

babaksd commented Jan 5, 2024

@deki That's great, Thank you for the amazing work!

deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 25, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 25, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 25, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 25, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 25, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 25, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 26, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 26, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 26, 2024
deki added a commit to olegz/aws-serverless-java-container that referenced this issue Jan 30, 2024
deki added a commit that referenced this issue Jan 30, 2024
@deki
Copy link
Collaborator

deki commented Jan 30, 2024

#739 has been merged and will be part of the next release. We've also added a sample: https://github.com/aws/serverless-java-container/tree/main/samples/springboot3/pet-store-native

@deki deki closed this as completed Jan 30, 2024
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

6 participants