cft

Building REST API using AWS with Serverless, Node.js, Express

Building REST API using AWS with Serverless, Node.js, Express


user

Salah Elhossiny Othman

3 years ago | 1 min read

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

Coming part for how to use Dyanmodb as a data resource for enriching API.


Upvote


user
Created by

Salah Elhossiny Othman

I’m currently working as FullStack ML developer. AWS Community Builder. Former fullstack developer at Surv* ( https://www.survbetter.com/ ) I’m currently learning Python, Ruby, ASP.NET Core. I’m looking to collaborate on opensource projects. I'm certified AWS ML specialist.


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles