TLDR - Take existing Express.js apps and host them easily onto cheap, auto-scaling, serverless infrastructure on AWS Lambda and AWS HTTP API with Serverless Express. It’s packed loads of production-ready features, like custom domains, SSL certificates, canary deployments, and costs ~$0.000003 per request.
If you simply want to host a common Express.js Node.js application, have it auto-scale to billions of requests, and charge you only when it’s used, we have something special for you…
Announcing Serverless Express, a Serverless Framework offering enabling you to easily host and manage Express.js applications on AWS Lambda and the new AWS HTTP API, which is 60% faster and 71% cheaper than their initial API Gateway product.
Serverless Expess is a pure Express.js experience and it’s perfect for those that want to focus on apps, not infrastructure complexity.
Here are the highlights:
Here is how to get started and deliver a Serverless Express.js based API with a custom domain, free SSL certificate and much more! You can also check out our Serverless Fullstack Application boilerplate, which includes Serverless Express in a real-world example that features a database, website using React and more.
Serverless Express is a Serverless Framework Component (i.e premium experiences for popular serverless use-cases) and you’ll need to install Node.js and the Serverless Framework CLI to use it.
Install Node.js here.
Then run this command to install Serverless Framework.
npm i -g serverless
Next, install the Serverless Express template:
serverless create --template-url https://github.com/serverless/components/tree/master/templates/express
Lastly, Serverless Express deploys onto your own Amazon Web Services account, so you’ll need Access Keys to an AWS account you own. Follow this guide to create those.
After you have created AWS Access Keys you can add them directly to an .env
file, or reference an AWS Profile in a .env
file, within the root of the template you installed.
AWS_ACCESS_KEY_ID=123456789
AWS_SECRET_ACCESS_KEY=123456789
You can also reference an AWS Profile in a .env
file like this.
AWS_PROFILE=default
If you don’t include a .env
file, the Serverless Framework will automatically look for a default
AWS Profile in the root folder of your machine.
Also, Serverless Framework has a built-in stages
concept. If you change the stage
it will deploy a totally separate copy of your serverless application.
# serverless.yml
component: express@1.0.8
name: express-api
stage: prod
Even better, you can use different .env
files for each stage
by simply using this convention:
.env # all stages
.env.dev # "dev" stage
.env.prod # "prod" stage
One last—often overlooked—step is to install the Express.js dependency, by running npm i
in the template.
#serverless #apis #aws #aws lambda #aws http api