Building REST API using AWS with Serverless, Node.js, Express
Getting started
To get started, you'll need the Serverless Framework installed. You'll also need your environment configured with AWS credentials.
Then, let's install a few dependencies. We'll install the express framework, as well as the serverless-http:
$ npm install --save express serverless-http
Then create a file index.js and initialize it like so:
const serverless = require('serverless-http');
const express = require('express')
const app = express()
app.get('/', function (req, res) {
res.send('Hello World!')
})
module.exports.handler = serverless(app);
The serverless-http package is a handy piece of middleware that handles the interface between your Node.js application and the specifics of API Gateway.
Then create a file serverless.yml:
service: my-express-application
provider:
name: aws
runtime: nodejs6.10
stage: dev
region: us-east-1
functions:
app:
handler: index.handler
events:
- http: ANY /
- http: 'ANY {proxy+}'
Now deploy
$ sls deploy
Hooray! congratulations :D
Coming part for how to use Dyanmodb as a data resource for enriching API.
resources : Book: Full Stack Serverless: Modern Application Development for Nader Dabit serverless.com/blog/serverless-express-rest..