Sample serverless application written in Java compiled with GraalVM native-image

Overview

Serverless GraalVM Demo

build

Architecture diagram

This is a simple serverless application built in Java and uses the GraalVM native-image tool. It consists of an Amazon API Gateway backed by four AWS Lambda functions and an Amazon DynamoDB table for storage.

Requirements

Software

Within the software folder is the products maven project. This single maven project contains all the code for all four Lambda functions. It uses the hexagonal architecture pattern to decouple the entry points, from the main domain logic and the storage logic.

Custom Runtime

The GraalVM native-image tool will produce a stand-alone executable binary. This does not require the JVM to run. To run our application on Lambda we must make a custom runtime and implement the Lambda Runtime API. This is done my including the aws-lambda-java-runtime-interface-client dependency in our project. The maven assembly build plugin is used to create a zip file which includes the executable binary as well as the entry point bootstrap file.

AWS Lambda execution environment

Infrastructure

Deployment

Deploy the demo to your AWS account using AWS CDK.

cdk deploy

The command cdk deploy will first build the products maven project using a docker build image with all the required GraalVM tools. Then it will use AWS CloudFormation to deploy the resources to your account.

CDK will create an output of the API Gateway endpoint URL for future use in our load tests.

Load Test

Artillery is used to make 300 requests / second for 10 minutes to our API endpoints. You can run this with the following command.

cd load-test
./run-load-test.sh

This is a demanding load test, to change the rate alter the arrivalRate value in load-test.yml.

CloudWatch Logs Insights

Using this CloudWatch Logs Insights query you can analyse the latency of the requests made to the Lambda functions.

The query separates cold starts from other requests and then gives you p50, p90 and p99 percentiles.

filter @type="REPORT"
| fields greatest(@initDuration, 0) + @duration as duration, ispresent(@initDuration) as coldStart
| stats count(*) as count, pct(duration, 50) as p50, pct(duration, 90) as p90, pct(duration, 99) as p99, max(duration) as max by coldStart

CloudWatch Logs Insights results

AWS X-Ray Tracing

You can add additional detail to your X-Ray tracing by adding a TracingInterceptor to your AWS SDK clients. Here is the code for my DynamoDbClient from the DynamoDbProductStore class.

private final DynamoDbClient dynamoDbClient=DynamoDbClient.builder()
        .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
        .region(Region.of(System.getenv(SdkSystemSetting.AWS_REGION.environmentVariable())))
        .overrideConfiguration(ClientOverrideConfiguration.builder()
        .addExecutionInterceptor(new TracingInterceptor())
        .build())
        .build();

Example cold start trace

Cold start X-Ray trace

Example warm start trace

Warm start X-Ray trace

👀 With other languages

You can find implementations of this project in other languages here:

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

Comments
  • Powertools (1.12.2) usage with graalvm

    Powertools (1.12.2) usage with graalvm

    Issue #, if available:

    Description of changes: Added reflect config for powertools , dependencies of powertools in pom and annotations for logging, metrics and tracing in java classes.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by ganvamsi 2
  • GraalVM Hint Processors added

    GraalVM Hint Processors added

    GraalVMHints added to replace manual graalvm configs

    Remove manual hard coded JSON files configurations for GraalVM native-image, and replace them with type-safe, better options that is full compile time processing annotation processors, that allow for better readability, type-safety and project manageability

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by GoodforGod 2
  • Anyone got this working from a Apple Silicon mac?

    Anyone got this working from a Apple Silicon mac?

    We really would love to use graalvm and build arm lambdas from our macs but are struggling to get this sample working.

    Do anyone have an approach to get this working?

    We have tried building our own docker image with using the new dev build of graalvm which should be working on m1 /apple silicon

    But without success

    Any ideas/thoughts?

    Thanx in advance Steffen

    Here is our dockerfile

    FROM arm64v8/amazonlinux:2

    RUN yum -y update
    && yum install -y tar unzip gzip bzip2-devel ed gcc gcc-c++ gcc-gfortran
    less libcurl-devel openssl openssl-devel readline-devel xz-devel
    zlib-devel glibc-static libcxx libcxx-devel llvm-toolset-7 zlib-static
    && rm -rf /var/cache/yum

    ENV GRAAL_VERSION 22.2.0-dev ENV GRAAL_FOLDERNAME graalvm-ce-java17-${GRAAL_VERSION} ENV GRAAL_FILENAME graalvm-ce-java17-linux-aarch64-${GRAAL_VERSION}.tar.gz RUN curl -4 -L https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/22.2.0-dev-20220323_0052/graalvm-ce-java17-linux-aarch64-dev.tar.gz | tar -xvz RUN mv $GRAAL_FOLDERNAME /usr/lib/graalvm RUN rm -rf $GRAAL_FOLDERNAME

    Graal maven plugin requires Maven 3.3.x

    ENV MVN_VERSION 3.6.3 ENV MVN_FOLDERNAME apache-maven-${MVN_VERSION} ENV MVN_FILENAME apache-maven-${MVN_VERSION}-bin.tar.gz RUN curl -4 -L https://mirrors.ukfast.co.uk/sites/ftp.apache.org/maven/maven-3/${MVN_VERSION}/binaries/${MVN_FILENAME} | tar -xvz RUN mv $MVN_FOLDERNAME /usr/lib/maven RUN rm -rf $MVN_FOLDERNAME

    Gradle

    ENV GRADLE_VERSION 7.4.1 ENV GRADLE_FOLDERNAME gradle-${GRADLE_VERSION} ENV GRADLE_FILENAME gradle-${GRADLE_VERSION}-bin.zip RUN curl -LO https://downloads.gradle-dn.com/distributions/gradle-${GRADLE_VERSION}-bin.zip RUN unzip gradle-${GRADLE_VERSION}-bin.zip RUN mv $GRADLE_FOLDERNAME /usr/lib/gradle RUN rm -rf $GRADLE_FOLDERNAME

    VOLUME /project WORKDIR /project

    RUN /usr/lib/graalvm/bin/gu install native-image RUN ln -s /usr/lib/graalvm/bin/native-image /usr/bin/native-image RUN ln -s /usr/lib/maven/bin/mvn /usr/bin/mvn RUN ln -s /usr/lib/gradle/bin/gradle /usr/bin/gradle

    ENV JAVA_HOME /usr/lib/graalvm

    ENTRYPOINT ["sh"]

    opened by stejsj 2
  • Fix typo in README

    Fix typo in README

    Fix a typo in README.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by psumiya 1
  • Upgrading to GraalVM 22.2.0

    Upgrading to GraalVM 22.2.0

    Issue #, if available: https://github.com/aws-samples/serverless-graalvm-demo/issues/13

    Description of changes: As well as updating the version of GraalVM, I took some time to remove build args which weren't required, to reduce the noise.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by msailes 0
  • Upgrading to GraalVM 22.2.0

    Upgrading to GraalVM 22.2.0

    Issue #, if available: https://github.com/aws-samples/serverless-graalvm-demo/issues/13

    Description of changes: As well as updating the version of GraalVM, I took some time to remove build args which weren't required, to reduce the noise.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by msailes 0
  • Updates to dependencies

    Updates to dependencies

    Issue #, if available: N/A

    Description of changes: Update to dependencies and the version of GraalVM used.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by msailes 0
  • Add root `pom.xml` and Maven wrapper

    Add root `pom.xml` and Maven wrapper

    pom.xml aggregating all modules simplifies importing project into IDEs and enables building both infrastructure and application code with single command.

    Also added Maven Wrapper (generated with mvn wrapper:wrapper) to ensure Maven version consistency across environments and simplify building projects for devs who do not have Maven installed.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by maciejwalkowiak 0
  • GitHub actions

    GitHub actions

    Issue #, if available:

    Description of changes:

    Add GraalVM native-image compilation as a GitHub action

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by msailes 0
  • Added the CRT client to the DynamoDbProductStore

    Added the CRT client to the DynamoDbProductStore

    Issue #, if available:

    Description of changes:

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by msailes 0
  • Add link to .NET examples

    Add link to .NET examples

    Issue #, if available:

    Add link to README for the .NET examples.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by jeastham1993 0
  • Powertools 1.12.2 with graalvm

    Powertools 1.12.2 with graalvm

    Issue #, if available:

    Description of changes: Added reflect config for powertools , dependencies of powertools in pom and annotations for logging, metrics and tracing in java classes.

    By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

    opened by ganvamsi 0
  • running `cdk deploy` changes the permissions of my target file to root?

    running `cdk deploy` changes the permissions of my target file to root?

    Hello. Thank you so much for this demo. I'm just having one little problem...

    Whenever I run cdk deploy, the permissions of my software/target directory get set to root. Because of this, I cannot run my tests in that directory (permission denied error.)

    I am on Linux, so to fix this, I need to run chown on my project to change the owner of the directory back to my user.

    Is there anyway to get around this besides running my mvn tests as root? Thank you.

    opened by franciskafieh 0
Owner
AWS Samples
AWS Samples
"Some" Utilities you can use for your Java projects "freely"! Files are compiled with Java-8 and above, but mostly Java-11.

✨ Java-SomeUtils ?? "Some" Utilities you can use for your Java projects "freely"! *"Freely"* forcing you to include the license into your program. Fil

JumperBot_ 2 Jan 6, 2023
A demo shopping cart Java Akka Serverless

shopping-cart-java-akka-serverless This project is an Akka Serverless service that demonstrates a simple shopping cart implemented as an Akka Serverle

Hugh McKee 7 Dec 3, 2021
Download compiled jar from packages or compile it by yourself from sources

idle_codes Install Download compiled jar from packages or compile it by yourself from sources Put the jar file wherever you want. Make sure you have J

null 8 Dec 31, 2021
RT4 client originally compiled on Jan 28, 2009 (530)

Goals Identify all classes Create new static classes by grouping related members Identify all methods Identify all fields Identify all local variables

Pazaz 10 Nov 14, 2022
Example React Native library written with JSI

react-native-jsi-example This is an example JSI Module for React Native that returns a value from C++ to JS synchronously. Implemented for just iOS. T

Enes 7 Mar 3, 2022
Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Bank Statement Analyzer Application that currently runs in terminal with the commands: javac Application.java java Application [file-name].csv GUI coming soon...

Hayden Hanson 0 May 21, 2022
Sample Spring Boot CLI application

sb-cli Sample Spring Boot CLI application. Shows how a Spring Boot application may be configured and packaged to create native executables with GraalV

Andres Almiray 28 Nov 2, 2022
A sample eForms application that can visualise an eForms notice

A sample eForms application that can visualise an eForms notice. It uses efx-translator-java to generate XSL templates from notice view templates written in EFX. It then uses an XSLT processor to generate an HTML visualisation of any given eForms notice.

TED & EU Public Procurement 6 Nov 23, 2022
Sceneform React Native AR Component using ARCore and Google Filament as 3D engine. This the Sceneform Maintained Component for React Native

Discord Server Join us on Discord if you need a hand or just want to talk about Sceneform and AR. Features Remote and local assets Augmented Faces Clo

SceneView Open Community 42 Dec 17, 2022
React native wrapper for Jitsi Meet SDK Library that rely on the native view (Activity / ViewController)

react-native-jitsi-meet-sdk React native wrapper for Jitsi Meet SDK Library. This Library implements the Jitsi SDK with a native activity on the Andro

null 7 May 2, 2022
With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any other file server

React Native In-App update With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any o

Nepein Andrey 7 Dec 21, 2022
An awesome native wheel picker component for React Native.

⛏️ react-native-picky An awesome native wheel picker component for react-native. Features Supports multiple columns ✅ Supports looping ✅ Native Androi

null 28 Dec 4, 2022
Image Cropping Library for Android

uCrop - Image Cropping Library for Android This project aims to provide an ultimate and flexible image cropping experience. Made in Yalantis How We Cr

Yalantis 11.4k Jan 2, 2023
A simple app to use Xposed without root, unlock the bootloader or modify system image, etc.

中文文档 Introduction VirtualXposed is a simple App based on VirtualApp and epic that allows you to use an Xposed Module without needing to root, unlock t

VirtualXposed 14k Jan 8, 2023
An image loading and caching library for Android focused on smooth scrolling

Glide | View Glide's documentation | 简体中文文档 | Report an issue with Glide Glide is a fast and efficient open source media management and image loading

Bump Technologies 33.2k Dec 31, 2022
A powerful image downloading and caching library for Android

Picasso A powerful image downloading and caching library for Android For more information please see the website Download Download the latest AAR from

Square 18.4k Dec 31, 2022
Example usage of work manager in Android, while doing this study, image downloading was preferred as a method.

android-workmanager-example Example usage of work manager in Android, while doing this study, image downloading was preferred as a method. Java 11 com

Adil Çetin 1 Jan 29, 2022
Shows Image you select on Top of every Window by holding the button you choose

ImageOnTop What it does? Shows Image you select on Top of every Window by holding the button you choose. How to use it? Press a keyboard key you want

null 1 Jan 23, 2022
Small app to create icon sets for Linux, Windows, OSX, Android and IOS from a single PNG image

FXIconcreator Small app to create icon sets (multi resolution) for Linux, Windows, OSX from a single PNG image Reason for creating such an app was tha

null 18 Aug 4, 2022