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

"8 1-2 things about serverless (with node.js)" ...

"8 1-2 things about serverless (with node.js)" - HolyJS Piter 2017

What is serverless? How does it work? Can you explain it with something as simple as Lego bricks?

This talk will answer that and at least six and a half more questions. It’s main goal is to explain serverless architecture, show you why it’s important, and finally, show you why it works great with Node.js and how to use it.

https://holyjs-piter.ru/en/talks/the-hitchhikers-guide-to-the-serverless-galaxy/

Slobodan Stojanović

June 02, 2017
Tweet

More Decks by Slobodan Stojanović

Other Decks in Programming

Transcript

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

    ORGANIZER github.com/stojanovic twitter.com/slobodan_ SLOBODAN STOJANOVIĆ
  2. #holyjs @slobodan_ • WHAT IS SERVERLESS? • 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? • IS SERVERLESS SECURE?
  3. #holyjs @slobodan_ And if no one is using some service

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

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

    PARTS THAT YOU ARE USING AT THE MOMENT
  6. #holyjs @slobodan_ • HTTP REQUEST (API) • FILE • NOTIFICATION

    • MAIL • STREAM • MANY OTHER THINGS WHAT CAN TRIGGER SERVERLESS FUNCTION
  7. #holyjs @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
  8. #holyjs @slobodan_ • TIMEOUT UP TO 300 SECONDS • 128MB

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

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

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

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

    callback) => { console.log(‘“Hello”: ”World”’) callback(null, {“Hello”: ”World”}) } hello-world.js
  13. #holyjs @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
  14. #holyjs @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
  15. #holyjs @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
  16. #holyjs @slobodan_ ‘use strict’ const Api = require(‘claudia-api-builder‘) const api

    = new Api() const jokes = require(‘./jokes.json’) api.get(‘/‘, () => jokes) module.exports = api api.js
  17. #holyjs @slobodan_ { "lambda": { "role": "chuck-norris-api-executor", "name": "chuck-norris-api", "region":

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

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

    = new Api() const jokes = require(‘./jokes.json’) api.get(‘/‘, () => jokes) api.get(‘/{id}’, req => jokes.filter(joke => joke.id === req.pathParams.id ))) api.get(‘/random‘, () => jokes[ Math.floor(Math.random() * jokes.length) ]) module.exports = api api.js
  20. #holyjs @slobodan_ // … api.get(‘/{id}’, req => { console.log(req.pathParams) return

    jokes.filter(joke => joke.id === req.pathParams.id ) }) // … api.js
  21. #holyjs @slobodan_ { "nextForwardToken": “f/33366982080235359…”, "events": [ { … },

    { "ingestionTime": 1496227223886, "timestamp": 1496227223884, "message": “2017-05-31T10:40:23.805Z\t8d2-45ed…\t{ id: '42' }\n" }, { … }, { … } ], "nextBackwardToken": “b/333669820769…” } OUTPUT
  22. #holyjs @slobodan_ { "nextForwardToken": “f/33366982080235359…”, "events": [ { … },

    { "ingestionTime": 1496227223886, "timestamp": 1496227223884, "message": “2017-05-31T10:40:23.805Z\t8d2-45ed…\t{ id: '42' }\n" }, { … }, { … } ], "nextBackwardToken": “b/333669820769…” } OUTPUT
  23. #holyjs @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
  24. #holyjs @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
  25. #holyjs @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
  26. #holyjs @slobodan_ • BAD CODE • BAD PERMISSIONS • 3RD

    PARTY LIBRARIES • PROBLEMS WITH OTHER BUILDING BLOCKS,
 SUCH AS SQL INJECTION • KEYS AND SECRETS PROBLEMS
  27. #holyjs @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