AWS | Express API Example

This template demonstrates how to develop and deploy a simple Node Express API running on AWS Lambda using the traditional Serverless Framework.

Clone This Example

Step #1 - npm install serverless -g
Step #2 - serverless install -u -n  aws-node-express-api

Serverless Framework Node Express API on AWS

This template demonstrates how to develop and deploy a simple Node Express API service running on AWS Lambda using the traditional Serverless Framework.

Anatomy of the template

This template configures a single function, api, which is responsible for handling all incoming requests thanks to configured http events. To learn more about http event configuration options, please refer to http event docs. As the events are configured in a way to accept all incoming requests, express framework is responsible for routing and handling requests internally. Implementation takes advantage of serverless-http package, which allows you to wrap existing express applications. To learn more about serverless-http, please refer to corresponding GitHub repository.



This example is made to work with the Serverless Framework dashboard, which includes advanced features such as CI/CD, monitoring, metrics, etc.

In order to deploy with dashboard, you need to first login with:

serverless login

install dependencies with:

npm install

and then perform deployment with:

serverless deploy

After running deploy, you should see output similar to:

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service file to S3 (711.23 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
Serverless: Stack update finished...
Service Information
service: aws-node-express-api
stage: dev
region: us-east-1
stack: aws-node-express-api-dev
resources: 12
api keys:
  ANY -
  ANY -{proxy+}
  api: aws-node-express-api-dev-api

Note: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to http event docs.


After successful deployment, you can call the created application via HTTP:


Which should result in the following response:

{"message":"Hello from root!"}

Calling the /hello path with:


Should result in the following response:

{"message":"Hello from path!"}

If you try to invoke a path or method that does not have a configured handler, e.g. with:


You should receive the following response:

{"error":"Not Found"}

Local development

It is also possible to emulate API Gateway and Lambda locally by using serverless-offline plugin. In order to do that, execute the following command:

serverless plugin install -n serverless-offline

It will add the serverless-offline plugin to devDependencies in package.json file as well as will add it to plugins in serverless.yml.

After installation, you can start local emulation with:

serverless offline

To learn more about the capabilities of serverless-offline, please refer to its GitHub repository.

view on Github

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g