All Projects → aws-samples → serverless-graalvm-demo

aws-samples / serverless-graalvm-demo

Licence: MIT-0 license
Sample serverless application written in Java compiled with GraalVM native-image

Programming Languages

java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to serverless-graalvm-demo

netlify-lambda-function-example
An example Netlify Lambda function that processes payments with Stripe.
Stars: ✭ 93 (-29.55%)
Mutual labels:  lambda
FancyDialog
Kotlin + DSL风格代替传统的Builder模式 诸多可配置项 高阶函数代替自定义回调接口 书写起来超级顺手
Stars: ✭ 24 (-81.82%)
Mutual labels:  lambda
jenkinsfile-runner-lambda
Run Jenkinsfiles in AWS Lambda
Stars: ✭ 52 (-60.61%)
Mutual labels:  lambda
serverless-lumigo-plugin
Serverless monitoring and troubleshooting plugin to easily apply distributed tracing
Stars: ✭ 59 (-55.3%)
Mutual labels:  lambda
serverless-certificate-creator
serverless plugin to manage the certificate of your lambdas custom domain (API Gateway=
Stars: ✭ 33 (-75%)
Mutual labels:  lambda
serverless-image-rendering
Image delivery with AWS Lambda ⚡
Stars: ✭ 43 (-67.42%)
Mutual labels:  lambda
lambdakiq
ActiveJob on SQS & Lambda
Stars: ✭ 131 (-0.76%)
Mutual labels:  lambda
s3-monitoring
No description or website provided.
Stars: ✭ 14 (-89.39%)
Mutual labels:  lambda
spark-java8
Java 8 and Spark learning through examples
Stars: ✭ 40 (-69.7%)
Mutual labels:  lambda
lambda-example
Example REST service for a Lambda article I wrote
Stars: ✭ 23 (-82.58%)
Mutual labels:  lambda
aws-is-how
Know How Guide and Hands on Guide for AWS
Stars: ✭ 27 (-79.55%)
Mutual labels:  lambda
ebs-snapshot-lambda
AWS lambda function to snapshot EBS volumes and purge old snapshots.
Stars: ✭ 37 (-71.97%)
Mutual labels:  lambda
lambda-runtime-pypy3.5
AWS Lambda Runtime for PyPy 3.5
Stars: ✭ 17 (-87.12%)
Mutual labels:  lambda
imprenta
An AWS lambda in python 3 that generates PDF files from HTML using jinja, pdfkit and wkhtmltopdf.
Stars: ✭ 18 (-86.36%)
Mutual labels:  lambda
aws-cloudformation-cognito-identity-pool
A Lambda-backed Custom Resource for a Cognito Identity Pool in CloudFormation
Stars: ✭ 35 (-73.48%)
Mutual labels:  lambda
Hands-On-Serverless-Applications-with-Go
Hands-On Serverless Applications with Go, published by Packt.
Stars: ✭ 92 (-30.3%)
Mutual labels:  lambda
iot-button-ec2-controller
Allows the start/stop of EC2 instances using an AWS IoT button
Stars: ✭ 23 (-82.58%)
Mutual labels:  lambda
lambda2js
Converts a C# expression tree (from Linq namespace) to a syntatically correct javascript code.
Stars: ✭ 51 (-61.36%)
Mutual labels:  lambda
terraform-aws-efs-backup
Terraform module designed to easily backup EFS filesystems to S3 using DataPipeline
Stars: ✭ 40 (-69.7%)
Mutual labels:  lambda
lambda-lite-js
a tiny FUNCITONAL LANGUAGE implemented by javascript. 一个函数式语言,使用 js 实现。
Stars: ✭ 77 (-41.67%)
Mutual labels:  lambda

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 by 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].