This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 400,000 packages pre-installed, including express-on-serverless
with all npm
packages installed. Try it out:
require()
any package directly from npmawait
any promise instead of using callbacks (example)This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
Now you can run Node.js express on AWS Lambda, using Serverless framework!
I want to run express on AWS Lambda and deploy it using Serverless.
This can be run with express, koa or other Node.js servers as far as it is requestListener
Install npm modules and generate template.
npm install -g serverless
npm install -S express express-on-serverless
serverless create --template aws-nodejs
Modify handler.js and serverless.yml
// handler.js
const express = require('express')
const app = express()
app.get('/test', (req, res) => {
res.send("I'm fine!")
})
exports.index = require('express-on-serverless')(app)
// serverless.yml
service: aws-nodejs
provider:
name: aws
runtime: nodejs4.3
functions:
index:
handler: handler.index
events:
http: any {proxy+}
Deploy to AWS!
serverless deploy
Now you can access https://API_GATEWAY_HOST/dev/test
!
It's too easy!!