Skip to main content

AWS Lambda + Java

You can run your Restate services as serverless functions on AWS Lambda.

tip

The easiest way to run Restate handlers on AWS Lambda is to use the Restate CDK construct library.

Make sure you have defined a Lambda handler in your service code, as explained in the serving docs.

Configure the build tool to generate Fat-JARs so that all dependencies can be deployed to AWS Lambda as a single bundle. For example, using Gradle:


plugins {
// ...
// The shadow plugin generates a shadow JAR ready for AWS Lambda
id("com.github.johnrengelman.shadow").version("7.1.2")
// ...
}
// It's important to correctly merge log4j plugin and extension metadata, otherwise certain logging features may break
tasks.withType<ShadowJar> {
transform(Log4j2PluginsCacheFileTransformer::class.java)
transform(ServiceFileTransformer::class.java)
}

For a complete Gradle build script example please see the example hello-world-lambda-cdk.

Now build the Fat-JAR. For example, using Gradle:


gradle shadowJar

Then upload the generated Jar to AWS Lambda, and configure MyLambdaHandler as the Lambda class in the AWS UI.

Lambda service registration

Once your Lambda handler is deployed, register it with Restate as described in the registration docs. Make sure you first publish a new version of the Lambda function before registering it with Restate.