Is there any ability to use GraalVM to run Java in AWS Lambda functions? I read a lot articles about cold starts of Java applications with GraalVM AOT (ahead-of-time) compilation feature and decreasing duration of that and I'd like to try to use it in my AWS Lambda projects.
-
1Is this what you are looking for? It's a kind of a hack using Go... https://engineering.opsgenie.com/run-native-java-using-graalvm-in-aws-lambda-with-golang-ba86e27930bf – Fabio Manzano Aug 31 '18 at 14:56
-
7The aot compilation is supposed to improve the startup time of the application, it will not offer the best performance. Warmed up JIT will perhaps have better performance characteristics, but you ought to warm it up first. If you're using enterprise edition of GraalVM you can build the native image with --profile-guided-optimizations flag, apply load on the generated image to create a profile and build the final image with this profile taken into account for better performance (close to the warmed up JIT version), but it also depends on workload. – Oleg Šelajev Aug 31 '18 at 16:04
-
@OlegŠelajev thanks for your note, I updated a bit my question. – Hleb Aug 31 '18 at 20:13
-
1I'm not 100% sure, but I don't think there's currently a way to run anything except officially supported environments: https://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html. If you're interested exclusively in AWS lamdas, perhaps you indeed need to go through a different runtime first and load the native image into it as the article above suggests. – Oleg Šelajev Sep 03 '18 at 08:40
-
1If your interest is not limited to AWS lambda, and your faas provider allows you to run containers as the unit of deployment, then you can do something like the following post about using GraalVM native image on Fn project does: https://medium.com/criciumadev/serverless-native-java-functions-using-graalvm-and-fn-project-c9b10a4a4859 – Oleg Šelajev Sep 03 '18 at 08:41
-
@OlegŠelajev many thanks for your recommendations! – Hleb Sep 03 '18 at 08:43
-
2Just created a simple Micronaut function, natively compiled and deployed to Lambda. It's the prime number guide. Currently getting a latency/call time of 60ms. Not bad at all. – Kango_V Jan 22 '20 at 16:02
2 Answers
With the introduction of Custom AWS Lambda Runtimes at re:Invent 2018, this is now do-able. See further the AWS Lambda Runtime Interface
You can use the bootstrap shell script published at https://docs.aws.amazon.com/lambda/latest/dg/runtimes-walkthrough.html to invoke your GraalVM native image, or you can implement the bootstrap functionality in your native image.
There is also an interesting article in Japanese on an approach which uses Micronaut which Google can translate for you, and corresponding https://github.com/kencharos/try-graal-lambda though imho the case for using Micronaut here is not that compelling.

- 15,352
- 4
- 44
- 84
-
Yes, there are more articles about GraalVM on the custom runtimes for AWS Lambda, for example: https://medium.com/@mathiasdpunkt/fighting-cold-startup-issues-for-your-kotlin-lambda-with-graalvm-39d19b297730 I'm sure as time passes, there well be even more of them. – Oleg Šelajev Feb 08 '19 at 08:08
I have a full sample with Java+ GraalVM+ Custom Runtime with all deployments scripts even. Also, I compared the performance with the most popular runtimes:
https://github.com/Aleksandr-Filichkin/java-graalvm-aws-lambda

- 660
- 2
- 8
- 22