Locally Run an AWS Serverless Micronaut App

Micronaut has several advantages for getting started quickly in AWS Lambda. For my example, I’m using GraalVM to build a native fast Lambda function. I’m also using AWS CDK to deploy the function. Without further ado, let’s get started.

Prerequisites

  • Micronaut App
  • AWS CDK
  • AWS SAM
  • Docker

Build the Application

Building the software is simple enough. Execute the following command to build a native Lambda function and test it:

./gradlew :app:buildNativeLambda
./gradlew test

Run Locally

To run locally, go to the infra directory, create the template using cdk synth, and execute that template using sam:

cd infra
cdk synth
sam local start-api -t ./cdk.out/MicronautAppStack.template.json

That’s it. Your app should be running on http://localhost:3000

Preparing to Deploy

CDK will need to be bootstrapped. AWS recommends using an administrator account for bootstrapping.

cdk bootstrap

Deploying

Finally, whenever you are ready to deploy, perform the following steps:

cd infra
cdk synth
cdk deploy

The console will provide the URL to your newly deployed Lambda function. Good luck and happy hacking!