Giter VIP home page Giter VIP logo

serveless-nodejs-aws's Introduction

Serverless - Amazon Web service - NodeJs micro services

This purpose of this project is to show how Node.js micro services works with Amazon webservice. I will update this repository with a tutorial that shows how you are able to easily create a micro-service and setup that in Lambda and working with other services in AWS.

*** Angular Demo of Search an Comment and return response from Lambda***

Angular project is under Client folder

Development Requirement

before any steps, make sure you are in serverless folder, then :

  1. install serverless npm install serverless -g
  2. install dependencies npm install or alternatively use Yarn yarn install
  3. you need to setup AWS credentials as easy as sls config credentials --provider aws --key [you-key] --secrect [you-secrect]. The goal is to setup key and secret key if you are happy with other ways, do it then.
  4. serverless invoke local -f [function name] sls is short command of serverless you may want to use it.
  5. send your variables with event.json, for more information read serverless documentation.

Deployment

In order to deploy the function simply run

serverless deploy

if all goes ok then you should see API endpoint as well as other information.

Usage

In serverless.yml a function which is comment will have a GET endpoint to receive data from a third-party. Then it will create all information to a file with uuid name and save it in /tmp/ folder in Lambda. Then, that file will be uploaded to S3 under brandlab-inbox bucket which has a subfolder comments.

As soon as, any file is created in comments\*.json, commentParse which is another Lambda function will be triggered and that particular file will be parsed and will be sent to CloudWatch with the following Metrics.

Sample Return JSON

sample of return message after calling GET with an id=71

{
    "message":"Successfully uploaded data to S3",
    "body":{  
       "postId":15,
       "id":71,
       "name":"vel pariatur perferendis vero ab aut voluptates labore",
       "email":"[email protected]",
       "body":"mollitia magnam etnipsum consequatur est expeditanaut rem ut ex doloremque est vitae estncumque velit recusandae numquam libero dolor fuga fugit a"
    }
}

Logs

To verify that our event was forwarded to our log-function run

serverless logs -f comments

The expected result should be similar to:

START RequestId: 6155317e-f028-11e6-b22c-51eaabd15d33 Version: $LATEST
2017-02-11 15:04:51.563 (+08:00)        6155317e-f028-11e6-b22c-51eaabd15d33    Successfully uploaded data to S3
2017-02-11 15:04:51.579 (+08:00)        6155317e-f028-11e6-b22c-51eaabd15d33    Temp File Delete
END RequestId: 6155317e-f028-11e6-b22c-51eaabd15d33
REPORT RequestId: 6155317e-f028-11e6-b22c-51eaabd15d33  Duration: 660.13 ms     Billed Duration: 700 ms         Memory Size: 1024 MB    Max Memory Used: 35 MB  

you can see which file name has been uploaded to S3 and then that file been deleted from /tmp/.

serverless logs -f commentParse

and the expected result should be similar to:

START RequestId: 33c29257-f02e-11e6-8638-f9075e0278ef Version: $LATEST
2017-02-11 15:46:31.809 (+08:00)        33c29257-f02e-11e6-8638-f9075e0278ef    HAS BEEN READ FROM S3:  {"postId":11,"id":54,"name":"culpa eius tempora sit consequatur neque iure deserunt","email":"[email protected]","body":"et ipsa rem ullam cum pariatur similique quia\ncum ipsam est sed aut inventore\nprovident sequi commodi enim inventore assumenda aut aut\ntempora possimus soluta quia consequatur modi illo"}
END RequestId: 33c29257-f02e-11e6-8638-f9075e0278ef
REPORT RequestId: 33c29257-f02e-11e6-8638-f9075e0278ef  Duration: 128.54 ms     Billed Duration: 200 ms         Memory Size: 1024 MB    Max Memory Used: 33 MB  

serveless-nodejs-aws's People

Contributors

mhadaily avatar

Watchers

James Cloos avatar hamza tanji cherkaoui avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.