百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

serverless-graalvm-demo

> 编程语言
开源

使用 GraalVM 编译的 Java 编写的无服务器应用示例

195 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

使用 GraalVM 编译的 Java 编写的无服务器应用示例

Serverless GraalVM Demo

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

  • AWS CLI
  • AWS CDK
  • Java 21
  • Maven 3.5 +
  • Artillery for load-testing the application

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.

Infrastructure

Deployment

Deploy the demo to your AWS account using AWS CDK.

bash
cdk deploy --all

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.

bash
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

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.

java
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

Example warm start trace

With other languages

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

  • Rust
  • ️ TypeScript
  • ️ Go
  • ⭐ Groovy
  • Kotlin
  • .NET

Security

See CONTRIBUTING for more information.

License

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

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Javagraalvm-native-imagejavalambdaserverless

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言