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

The Hitchhikers Guide To The Serverless Galaxy ...

The Hitchhikers Guide To The Serverless Galaxy - AmsterdamJS

My presentation from AmsterdamJS 2017

Slobodan Stojanović

June 08, 2017
Tweet

More Decks by Slobodan Stojanović

Other Decks in Programming

Transcript

  1. #amsterdamjs @slobodan_ • WHAT IS SERVERLESS • HOW DOES IT

    WORK • HOW DOES IT WORK WITH NODE.JS • WHY IS IT IMPORTANT • WHEN SHOULD YOU USE IT
  2. #amsterdamjs @slobodan_ CTO AT CLOUD HORIZON AND JS BELGRADE MEETUP

    ORGANIZER github.com/stojanovic twitter.com/slobodan_ SLOBODAN STOJANOVIĆ
  3. #amsterdamjs @slobodan_ “JUST BELIEVE EVERYTHING I TELL YOU, AND IT

    WILL ALL BE VERY, VERY SIMPLE” AH, WELL, I'M NOT SURE I BELIEVE THAT
  4. #amsterdamjs @slobodan_ And if no one is using some service

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

    it’s simple to remove or replace it
  6. #amsterdamjs @slobodan_ JSON event { “body”:”…”, “headers”: “”, … }

    exports.handler = (event, context, callback) => { callback(null, {“Hello”: ”World”}) }
  7. #amsterdamjs @slobodan_ exports.handler = (event, context, callback) => { callback(null,

    {“Hello”: ”World”}) } JSON { “body”: { “Hello”:”World” }, “status”: 200, … }
  8. #amsterdamjs @slobodan_ • GOOD STARTUP PERFORMANCE • SMALL MODULES •

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

    callback) => { console.log(‘“Hello”: ”World”’) callback(null, {“Hello”: ”World”}) } hello-world.js
  10. #amsterdamjs @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
  11. #amsterdamjs @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
  12. #amsterdamjs @slobodan_ • npm i claudia -g • SET UP

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

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

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

    = new Api() const facts = require(‘./amsterdam.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
  16. #amsterdamjs @slobodan_ ‘use strict’ const Api = require(‘claudia-api-builder‘) const api

    = new Api() const facts = require(‘./amsterdam.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
  17. #amsterdamjs @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
  18. #amsterdamjs @slobodan_ “IT IS A MISTAKE TO THINK YOU CAN

    SOLVE ANY MAJOR PROBLEMS JUST WITH POTATOES”
  19. #amsterdamjs @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
  20. #amsterdamjs @slobodan_ • WEB API • BACKEND FOR THE SINGLE

    PAGE APP • CHATBOTS • QUICK PROTOTYPES THAT CAN EVOLVE TO 
 A REAL SOLUTIONS • PROCESSING FILES OR ANY KIND OF DATA • IoT • MANY, MANY OTHER THINGS
  21. #amsterdamjs @slobodan_ • SERVER “EXISTS” FOR FEW HUNDREDS OF MS

    • READ-ONLY, EXCEPT /TMP • NO DEDICATED SERVER • SANDBOX / CONTAINERS • NO CONFIGURATION • AUTO SCALING • AWS ECOSYSTEM AWS LAMBDA SECURITY
  22. #amsterdamjs @slobodan_ • BAD CODE • BAD PERMISSIONS • 3RD

    PARTY LIBRARIES • PROBLEMS WITH OTHER BUILDING BLOCKS,
 SUCH AS SQL INJECTION • KEYS AND SECRETS PROBLEMS
  23. #amsterdamjs @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 • GO AND TRY IT, IT’S EASY TO LEARN # SUMMARY