Upgrade to Pro — share decks privately, control downloads, hide ads and more …

8 ½ things about Serverless - FrontTalks

8 ½ things about Serverless - FrontTalks

FrontTalks 2017, Yekaterinsburg, Rusia

https://events.yandex.ru/events/fronttalks/2017/

Slobodan Stojanović

September 16, 2017
Tweet

More Decks by Slobodan Stojanović

Other Decks in Technology

Transcript

  1. #FrontTalks @slobodan_ CTO AT CLOUD HORIZON AND JS BELGRADE MEETUP

    ORGANIZER github.com/stojanovic twitter.com/slobodan_ SLOBODAN STOJANOVIĆ
  2. #FrontTalks @slobodan_ • WHAT IS SERVERLESS? • IS SERVERLESS ONLY

    ABOUT THE FUNCTIONS • HOW DOES IT WORK? • WHAT ARE THE SERVERLESS PLATFORMS? • HOW DOES IT WORK WITH NODE.JS? • HOW TO DEBUG SERVERLESS FUNCTION? • WHEN SHOULD YOU USE IT?
  3. #FrontTalks @slobodan_ And if no one is using some service

    it’s simple to remove or replace it
  4. #FrontTalks @slobodan_ And if no one is using some service

    it’s simple to remove or replace it
  5. #FrontTalks @slobodan_ ALSO IMAGINE THAT YOU PAY ONLY FOR THE

    PARTS THAT YOU ARE USING AT THE MOMENT
  6. #FrontTalks @slobodan_ JSON event { “body”:”…”, “headers”: “”, … }

    exports.handler = (event, context, cb) => { cb(null, { “Hello”: ”World” }) }
  7. #FrontTalks @slobodan_ JSON { “body”: { “Hello”:”World” }, “status”: 200,

    … } exports.handler = (event, context, cb) => { cb(null, { “Hello”: ”World” }) }
  8. #FrontTalks @slobodan_ • $0.20 PER 1 MILLION REQUESTS • FIRST

    MILLION REQUESTS / MONTH ARE FREE • $0.00001667 FOR EVERT GB-SECOND • FIRST 400.000 GB-SECONDS / MONTH ARE FREE
  9. #FrontTalks @slobodan_ • TIMEOUT UP TO 300 SECONDS • 128MB

    TO 1.5GB OF MEMORY • 500MB OF NON-PERSISTENT STORAGE (/TMP) • DEFAULT CONCURRENT EXECUTION LIMIT: 1000
  10. #FrontTalks @slobodan_ • NODE.JS • PYTHON • JAVA • C#

    • SHELL SCRIPTS • ANY EXECUTABLE AWS LAMBDA
  11. #FrontTalks @slobodan_ • NODE.JS • C# • F# • PYHON

    • PHP • SHELL SCRIPTS • ANY EXECUTABLE AZURE FUNCTIONS
  12. #FrontTalks @slobodan_ • GOOD STARTUP PERFORMANCE • SMALL MODULES •

    PERFORMANCE WITH LOW CPU AND MEMORY • SINGLE THREAD • EASY TO LEARN PROS
  13. #FrontTalks @slobodan_ ‘use strict’ console.log(‘Loading event’) exports.handler = (event, context,

    callback) => { console.log(‘“Hello”: ”World”’) callback(null, {“Hello”: ”World”}) } hello-world.js
  14. #FrontTalks @slobodan_ ‘use strict’ console.log(‘Loading event’) exports.handler = (event, context,

    callback) => { console.log(‘“Hello”: ”World”’) callback(null, {“Hello”: ”World”}) } hello-world.js
  15. #FrontTalks @slobodan_ • CREATE LAMBDA FUNCTION • UPLOAD ZIP FILE

    • CREATE API GATEWAY • SET TRIGGER • SET PERMISSIONS • ~11 MINS READ: http://amzn.to/2kciIEt HOW TO DEPLOY IT TO AWS
  16. #FrontTalks @slobodan_ IT’S LIKE FLYING FROM YEKATERINBURG TO HAWAII WITH

    LOW-COST DESTINATION IS AWESOME, BUT IT TAKES SOME TIME AND IT’S NOT THAT PLEASANT
  17. #FrontTalks @slobodan_ • DEPLOY AND UPDATE WITH SINGLE COMMAND •

    USE STANDARD NPM MODULES • NO BOILERPLATE, JUST FOCUS ON YOUR WORK • MANAGE MULTIPLE VERSIONS EASILY • GET STARTED QUICKLY, FLAT LEARNING CURVE MAIN CHARACTERISTICS
  18. #FrontTalks @slobodan_ • npm i claudia -g • SET UP

    AWS CREDENTIALS (ONE TIME) • mkdir claudia-api && cd $_ • npm init -f • npm i claudia-api-builder -S prepare
  19. #FrontTalks @slobodan_ ‘use strict’ const Api = require(‘claudia-api-builder‘) const api

    = new Api() const facts = require(‘./fun-facts.json’) api.get(‘/‘, () => facts) module.exports = api api.js
  20. #FrontTalks @slobodan_ { "lambda": { "role": "js-fun-executor", "name": "js-fun", "region":

    "eu-central-1" }, "api": { "id": "45qngjvkye", "module": "api", "url": "https://45qngjvkye.execute-api.eu- central-1.amazonaws.com/latest" } } RESULT
  21. #FrontTalks @slobodan_ ‘use strict’ const Api = require(‘claudia-api-builder‘) const api

    = new Api() const facts = require(‘./fun-facts.json’) api.get(‘/‘, () => facts) api.get(‘/{id}’, req => facts.filter(fact => fact.id === req.pathParams.id )) api.get(‘/random‘, () => facts[ Math.floor(Math.random() * facts.length) ]) module.exports = api api.js
  22. #FrontTalks @slobodan_ ‘use strict’ const Api = require(‘claudia-api-builder‘) const api

    = new Api() const facts = require(‘./fun-facts.json’) api.get(‘/‘, () => facts) api.get(‘/{id}’, req => facts.filter(fact => fact.id === req.pathParams.id )) api.get(‘/random‘, () => facts[ Math.floor(Math.random() * facts.length) ]) module.exports = api api.js
  23. #FrontTalks @slobodan_ api.get(‘/{id}’, req => { const filtered = facts.filter(fact

    => fact.id === req.pathParams.id ) console.log(‘Here >>’, filtered) return filtered }) api.js
  24. #FrontTalks @slobodan_ • REAL-TIME APPS WITH WEB SOCKETS • LOW-LATENCY

    APPS • WHEN YOU NEED CUSTOM SERVER CONFIG • WHEN YOU NEED COMPLIANCE • LONG RUNNING TASKS • COMPEX COMPUTING • WHEN YOU NEED TO PROVIDE SLA
  25. #FrontTalks @slobodan_ • WEB APIs • BACKEND FOR THE SINGLE

    PAGE APP • CHATBOTS • QUICK PROTOTYPES THAT CAN EVOLVE TO 
 A REAL SOLUTIONS • PROCESSING FILES OR ANY KIND OF DATA • IoT • MICROSERVICES • MANY, MANY OTHER THINGS
  26. #FrontTalks @slobodan_ • SERVERLESS IS FULLY MANAGED FaaS THAT
 HELPS

    YOU TO FOCUS ON YOUR BUSINESS LOGIC • EVENT-DRIVEN - MANY THINGS CAN TRIGGER FUNCTION • AUTO SCALING AND AUTO FAILOVER • IT WORKS NICE WITH NODE.JS • 3 MAJOR NODE.JS FRAMEWORKS • IT’S TRICKY TO DEBUG, SO WRITE TESTS • GO AND TRY IT, IT’S EASY TO LEARN # SUMMARY