Going ServerlessWITH AWS LAMBDA + NODEJS
JSJakartaJakarta JavaScript User Group
ABOUT ME
HI, I’M RIZA
facebook.com/rizafahmi
github.com/rizafahmi
medium.com/@rizafahmi22
@rizafahmi22
appscoast.id
Nov ‘13First Meetup
1.459Members
26Meetup Events
Held
100-ishAttendees per month
meetup.com/JakartaJS
JSJakartaJakarta JavaScript User Group
https://meetup.com/JakartaJS
https://jakartajs-join.herokuapp.com
JSJakartaJakarta JavaScript User Group
Serverless
“A New Cloud Computing Trend That Changes The Way You Think About
Writing And Maintaining Applications”
Tomasz JanczukChief Architect for Webtasks at Auth0
The Pieces
Lambda
EC2
EC2 ContainerService
ElasticBeanstalk
Lambda
What Lambda Really Is
Why You Should Use Lambda
Auto Scaling
Secure
Autoscale
Autoscale All The Way!
2010
2014 AWS Lambda
2016 Google Cloud FunctionsMicrosoft Azure Functions
2015 Webtask RadTonicDev
Functions Service Timeline
API Gateway
Databases
Other Services
“Serverless” Infrastructure
Use Cases
Scalable API
Scheduled Tasks
Indexing and Sync
Automation and iOT
Audit and Notification
Pricing
Free Tier
1M Request3M Seconds
of compute time
Lambda FunctionOur very first
Getting Started
Choose Your Weapon
Triggers
Write Your Code
1 'use strict'; 2 console.log('Loading function'); 3 4 exports.handler = (event, context, callback) => { 5 let min = 1 6 let max = 10 7 8 let random_number = Math.floor(Math.random() * 9 max) + min 10 let mark = "" 11 for (let i=min; i<random_number; i ++) 12 mark = mark + "!" 13 14 callback(null, "Hello Bandung" + mark) 15 }
Zooming in to code…
Setting it up!
Test it
Connecting Lambda To API Gateway
Create New API
Connect To Lambda Function
Publish it
Test it
Slack BotServerless
Add Slack WebHook Config
The Code 1 const AWS = require('aws-sdk') 2 const db = new AWS.DynamoDB.DocumentClient({region: 'ap-southeast-1'}) 3 4 exports.handler = (event, context, callback) => { 5 console.log(event) 6 if (event.user_name) { 7 const params = { 8 Item: { 9 date: Date.now(), 10 user_name: event.user_name 11 }, 12 TableName: 'report_log' 13 } 14 db.put(params, (err, data) => { 15 context.succeed({ 16 "response_type": "in_channel", 17 "text": "Hi " + event.user_name +"! It's time for standup meeting." 18 }) 19 }) 20 } 21 };
Setting Up The Database
Setting Up The Database
Permission To Use The DB
The Trigger
Publish it
Hook it
Hook it
Run it
Our Autoscaling And Maintenance Free Bot Is Finished
Now Let’s Build Skynet!
JSJakartaJakarta JavaScript User Group