Express Template

Running Express.js, or similar frameworks, in Lambda is common pattern that allows you to migrate to a more serverless architecture. The pattern is relatively simple.

A single function hosts your Express.js server, and routes all paths and methods to this Lambda function to allow Express.js to handle routing logic. This is a tradeoff in complexity. You have a simpler infrastructure, but more complex function.

We're going to build out a simple Todo App using Express. be using the @vendia/serverless-express package to run Express in a Lambda function.


It consists of the following resources:

  • API Gateway
  • Lambda Function
    • Express function: Hosts your Express.js server and all associated routing and business logic.
  • DynamoDB Table

Screenshot of Akeero showing the Express template


Once off steps needed to enable you to run CDK scripts to deploy infrastructure in your AWS account.

Getting Started

  1. Clone Express Demo repository locally
git clone https:/ 
  1. Install Dependencies:
cd express-todo
npm install
  1. Head to Akeero to generate a project from the Express template (Templates > Express Template)
  1. You should now be in the Diagram to Code canvas. First up let’s edit the project name
  1. Save the project locally, selecting the root folder of your web app.
  1. Go back to the terminal and install the relevant CDK and Akeero dependencies
cd akeero-cdk
npm install

If you have not bootstrapped CDK for the first time in your AWS account and AWS region, run the following. You only need to bootstrap an account and region once for CDK to work.

npx cdk bootstrap aws://ACCOUNT-NUMBER-1/REGION-1
  1. Run CDK Deploy
npx cdk deploy

This command will deploy your Express app!

Once deployed you should get the API Gateway domain of your site as an output for the command! Click on the link and you'll get a live running Todo app!

This is a simple example, but it can be applied to any existing Express app you're looking to migrate to AWS Lambda.

Happy building!