10.3 C
New York
Tuesday, October 28, 2025
Array

A practical guide to high-performance serverless with GraalVM and Spring



  1. Build the Docker image (e.g., native-compile-image).
  2. Run the container in the background.
  3. Copy the final zip archive from the container to the build agent’s local filesystem.
Bash


# Run the container in detached mode, giving it a name for reference
docker run -d --rm --name native-compile-container native-compile-image

# Copy the compiled zip file from the running container to the build agent's workspace
docker cp native-compile-container:/workspace/target/spring-serverless-function.zip./target/

This process leaves you with a single, deployable spring-serverless-function.zip file, which can then be uploaded to an artifact repository.

Deploying with the AWS CDK

With the deployment artifact ready, I can define the Lambda function using an infrastructure-as-code tool like the AWS Cloud Development Kit (CDK). The CDK code points to the zip file created by the pipeline and configures the Lambda function.

TypeScript


// Example CDK code for defining the Lambda function
import * as path from 'path';
import * as lambda from 'aws-cdk-lib/aws-lambda';

// Assuming 'this' is a CDK Stack context
const functionAssetDirectory = '/runtime/target/spring-serverless-function.zip';
const runtimeDir = path.join(__dirname, '..', functionAssetDirectory);

new lambda.Function(this, 'MyNativeLambda', {
  runtime: lambda.Runtime.PROVIDED_AL2023,
  code: lambda.Code.fromAsset(runtimeDir),
  handler: 'org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest',
  memorySize: 256,
  timeout: Duration.seconds(30),
  //... other configurations
});

Here, lambda.Runtime.PROVIDED_AL2023 specifies that we are using a custom runtime. The code property points to our zip archive. Crucially, the handler is still set to Spring’s generic FunctionInvoker.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

0FansLike
0FollowersFollow
0FollowersFollow
0SubscribersSubscribe
- Advertisement -spot_img

CATEGORIES & TAGS

- Advertisement -spot_img

LATEST COMMENTS

Most Popular

WhatsApp