This content originally appeared on DEV Community and was authored by Salah856
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
https://www.serverless.com/blog/serverless-express-rest-api
This content originally appeared on DEV Community and was authored by Salah856

Salah856 | Sciencx (2021-05-21T15:14:06+00:00) Building REST API using AWS with Serverless, Node.js, Express. Retrieved from https://www.scien.cx/2021/05/21/building-rest-api-using-aws-with-serverless-node-js-express/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.