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

8 ½ things about serverless - FDConf 2017

8 ½ things about serverless - FDConf 2017

Slobodan Stojanović

September 30, 2017
Tweet

More Decks by Slobodan Stojanović

Other Decks in Programming

Transcript

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

    ORGANIZER github.com/stojanovic twitter.com/slobodan_ SLOBODAN STOJANOVIĆ
  2. #FDConf @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. #FDConf @slobodan_ And if no one is using some service

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

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

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

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

    … } exports.handler = (event, context, cb) => { cb(null, { “Hello”: ”World” }) }
  8. #FDConf @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. #FDConf @slobodan_ • TIMEOUT UP TO 300 SECONDS • 128MB

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

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

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

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

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

    callback) => { console.log(‘“Hello”: ”World”’) callback(null, {“Hello”: ”World”}) } hello-world.js
  15. #FDConf @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. #FDConf @slobodan_ IT’S LIKE FLYING FROM MINSK TO HAWAII WITH

    LOW-COST DESTINATION IS AWESOME, BUT IT TAKES SOME TIME AND IT’S NOT THAT PLEASANT
  17. #FDConf @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. #FDConf @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. #FDConf @slobodan_ ‘use strict’ const Api = require(‘claudia-api-builder‘) const api

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

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

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

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

    => framework.id === req.pathParams.id ) console.log(‘Here >>’, filtered) return filtered }) api.js
  24. #FDConf @slobodan_ • CREATE AN API • CONNECT WITH DYNAMODB

    • ADD AUTHORIZATION • CONVERT IMAGES • BUILD A CHATBOT • LEARN HOW TO TEST AND DEBUG • LEARN GOOD ARCHITECTURE PRACTICES • MIGRATE EXPRESS APP TO SERVERLESS
  25. #FDConf @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
  26. #FDConf @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
  27. #FDConf @slobodan_ • SERVERLESS IS A TECHNOLOGY THAT COST YOU

    NOTHING IF NO-ONE IS USING IT • IT’S MORE THAN FUNCTIONS • FULLY MANAGED • FUNCTIONS ARE EVENT-DRIVEN - MANY TRIGGERS • AUTO SCALING AND AUTO FAILOVER • IT WORKS NICE WITH NODE.JS • IT’S TRICKY TO DEBUG, SO WRITE TESTS SUMMARY