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 …


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Building REST API using AWS with Serverless, Node.js, Express." Salah856 | Sciencx - Friday May 21, 2021, https://www.scien.cx/2021/05/21/building-rest-api-using-aws-with-serverless-node-js-express/
HARVARD
Salah856 | Sciencx Friday May 21, 2021 » Building REST API using AWS with Serverless, Node.js, Express., viewed ,<https://www.scien.cx/2021/05/21/building-rest-api-using-aws-with-serverless-node-js-express/>
VANCOUVER
Salah856 | Sciencx - » Building REST API using AWS with Serverless, Node.js, Express. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/21/building-rest-api-using-aws-with-serverless-node-js-express/
CHICAGO
" » Building REST API using AWS with Serverless, Node.js, Express." Salah856 | Sciencx - Accessed . https://www.scien.cx/2021/05/21/building-rest-api-using-aws-with-serverless-node-js-express/
IEEE
" » Building REST API using AWS with Serverless, Node.js, Express." Salah856 | Sciencx [Online]. Available: https://www.scien.cx/2021/05/21/building-rest-api-using-aws-with-serverless-node-js-express/. [Accessed: ]
rf:citation
» Building REST API using AWS with Serverless, Node.js, Express | Salah856 | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.