Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 1.06 KB

File metadata and controls

60 lines (41 loc) · 1.06 KB

Deploy an ExpressJs server on AWS lambda using Serverless

  1. Create a new project

sls create --template aws-nodejs --path my-service

  1. Install dependencies

npm install --save express serverless-http body-parser cors

  1. Create an index.js
// index.js

const serverless = require('serverless-http');
const express = require('express')
const cors = require('cors');
const app = express()

app.use(require("body-parser").json());
app.use(cors());

app.get('/', function (req, res) {
  res.send('Hello World!')
})

module.exports.handler = serverless(app);
  1. Update serverless.yml
# serverless.yml

service: my-express-application

provider:
 name: aws
 runtime: nodejs8.10
 stage: dev
 region: ap-southeast-2

functions:
    app:
      handler: index.handler
      events:
        - http: ANY /
          cors: true
        - http: 'ANY {proxy+}'
          cors: true
  1. Deploy your function

sls deploy -d

Reference

https://serverless.com/blog/serverless-express-rest-api/