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

Spring Native Zip File Support for AWS Lambda #108

Open
3 tasks
shresthaujjwal opened this issue Apr 29, 2021 · 8 comments
Open
3 tasks

Spring Native Zip File Support for AWS Lambda #108

shresthaujjwal opened this issue Apr 29, 2021 · 8 comments
Labels
type:enhancement A general enhancement

Comments

@shresthaujjwal
Copy link

What happened?

Deploy Spring Native Zip to AWS Lambda in zip format.
https://github.com/spring-projects-experimental/spring-native/blob/main/samples/cloud-function-aws/pom.xml#L58-L81

  • What were you attempting to do?
    Trying to deploy spring cloud functions to aws lambda in zip format.

  • What did you expect to happen?
    Expecting a zip file in project target which can be deployed to aws lambda.

  • What was the actual behavior? Please provide log output, if possible.
    Currently it is only possible to generate native image in docker.

Checklist

  • I have included log output.
  • The log output includes an error message.
  • I have included steps for reproduction.
@dmikusa
Copy link
Contributor

dmikusa commented Apr 29, 2021

This is an interesting request and if there's something we can do to make deploying to AWS easier, I'd support it. Again, I would appreciate it if you could share some more details though.

A few questions/thoughts...

Deploy Spring Native Zip to AWS Lambda in zip format.
https://github.com/spring-projects-experimental/spring-native/blob/main/samples/cloud-function-aws/pom.xml#L58-L81

So long as this only needs configuration in your Maven pom.xml file, you should be able to do this now. I suspect what will happen though is that you'll end up with is a container inside of which is the zip file. Is that what you're seeing at the moment?

Currently it is only possible to generate native image in docker.

Correct. This isn't specific to the Java Native Image buildpack. It is the primary goal of the buildpacks project, to take source code and transform that into container images.

You could try to extract files from the generated container images, but that's outside the scope of buildpacks. You'd need to look at Docker and any other tools that would let you pull files out of a container image.

I haven't used AWS Lambdas myself, is there a way you can deploy your code as a container image? If so and there are docs you could link me to, I'd be happy to take a look.

@dmikusa dmikusa added the type:enhancement A general enhancement label Apr 29, 2021
@shresthaujjwal
Copy link
Author

shresthaujjwal commented Apr 29, 2021

So long as this only needs configuration in your Maven pom.xml file, you should be able to do this now. I suspect what will happen though is that you'll end up with is a container inside of which is the zip file. Is that what you're seeing at the moment?

This is not possible (I think) as this step has to happen at the end after the native image has been generated. Basically, we have to take the native image which is part of OCI image and zip it up or create a shaded jar

You could try to extract files from the generated container images, but that's outside the scope of buildpacks. You'd need to look at Docker and any other tools that would let you pull files out of a container image.

Yes, we will probably have to do some extra scripting to extract that image and zip it up. Tying to see if we can automate this step as well. So that it would be easier to deploy to AWS Lambda.

I haven't used AWS Lambdas myself, is there a way you can deploy your code as a container image?

Yes, AWS Lambda does support Docker, but i was trying to see if i can deploy it without Docker. It would be great to have support for Functions. https://spring.io/projects/spring-cloud-function. So that we just upload jar/zip to AWS functions with handler.
https://github.com/spring-cloud/spring-cloud-function/blob/master/spring-cloud-function-samples

@shresthaujjwal
Copy link
Author

@dmikusa-pivotal just checking to see if you have any questions on this

@dmikusa
Copy link
Contributor

dmikusa commented May 5, 2021

Yes, we will probably have to do some extra scripting to extract that image and zip it up. Tying to see if we can automate this step as well. So that it would be easier to deploy to AWS Lambda.

I don't want to say it'll never happen, but the goal of buildpacks is to produce an image so the extraction work, at least for the foreseeable future is something you'll need to handle. If it's helpful, I could see the buildpack zipping up the resulting native image, possibly an env variable flag you set to instruct it to zip up the resulting image. Is there a particular format for the zip? or is it just a zip with the single binary?

Yes, AWS Lambda does support Docker, but i was trying to see if i can deploy it without Docker. It would be great to have support for Functions. https://spring.io/projects/spring-cloud-function. So that we just upload jar/zip to AWS functions with handler.

I would like to look at this more but haven't had the time. Apologizes. I suspect this is probably the preferred integration path for the two services, given that the stated goal of buildpacks is to produce an image. Plus really small images, like if you're building with the tiny builder do not add much in the way of overhead, maybe 10-15M. There are probably ways to strip that down as well, given some exploration and investigation.

tl;dr - I can't promise anything soon on this, but I would like to keep this open as a potential improvement.

@dmikusa
Copy link
Contributor

dmikusa commented May 25, 2021

FYI, a colleague of mine put together this simple extraction process in Maven, which is convenient.

https://github.com/making/hello-native-world/blob/main/pom.xml#L104-L138

He's using it for Azure Functions, but I think AWS Lambda is probably going to be very similar. Hope that helps!

@shresthaujjwal
Copy link
Author

This is great. I will test it out and share my findings

@Richardmbs12
Copy link

It would be very very valuable to be able to generate a native image that's compatible to run on lambda (using aws's base image)

@dmikusa
Copy link
Contributor

dmikusa commented Sep 1, 2021

It would be very very valuable to be able to generate a native image that's compatible to run on lambda (using aws's base image)

@Richardmbs12 We can certainly explore doing this. Can you expand on this idea? What specifically would you like it to do that you can't do now? Do you have any docs you can reference for AWS regarding their base image? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants