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***
before any steps, make sure you are in serverless
folder, then :
- install serverless
npm install serverless -g
- install dependencies
npm install
or alternatively use Yarnyarn install
- 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. serverless invoke local -f [function name]
sls is short command of serverless you may want to use it.- send your variables with event.json, for more information read serverless documentation.
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.
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 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":"Lavinia@lafayette.me",
"body":"mollitia magnam etnipsum consequatur est expeditanaut rem ut ex doloremque est vitae estncumque velit recusandae numquam libero dolor fuga fugit a"
}
}
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":"Kenton_Vandervort@friedrich.com","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