Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Going Serverless with OpenWhisk

289 views

Published on

For my talk at DevNexus 2018.

Published in: Technology
  • Be the first to comment

Going Serverless with OpenWhisk

  1. 1. GOING SERVERLESS WITH OPENWHISK RAYMOND CAMDEN
  2. 2. WHY AM I HERE? • Developer Advocate for IBM • LoopBack, OpenWhisk, Node.js, Cordova, web stuff, and cats • Blogging at raymondcamden.com • Tweeting at @raymondcamden
  3. 3. CONGRATULATIONS! • New job! • CTO of the Galactic Empire • Full discretion! • Build the Future of the Empire!
  4. 4. CURRENT SYSTEM • J2EE servers • Oracle • Monolithic, slow to update • One change requires 10 people to sign off, 10 unit tests, a Star Destroyer, and a full day of Jenkins deployment
  5. 5. NEW SYSTEM • Node/JavaScript • Microservices • Serverless
  6. 6. LETS TALK ABOUT THAT NAME… “Serverless”
  7. 7. WHAT IS SERVERLESS? “Serverless computing refers to a model where the existence of servers is simply hidden from developers. I.e. that even though servers still exist developers are relieved from the need to care about their operation. They are relieved from the need to worry about low- level infrastructural and operational details such as scalability, high-availability, infrastructure-security, and so forth.” Credit: A dead link at IBM
  8. 8. “FUNCTION AS A SERVICE” • I write a function and it does one thing • The actual hosting of the function, the making it available, is handled by the service • I call my function • “Details”
  9. 9. APACHE OPENWHISK (OPENWHISK.ORG)
  10. 10. INSTALLATION • Focused on the IBM Cloud (Bluemix) path • https://console.ng.bluemix.net/openwhisk/
  11. 11. TASK ONE Stormtroopers get armor 1 Armor needs paint 2 What color should it be? 3
  12. 12. ACTIONS!
  13. 13. ACTIONS ARE… • Small, atomic, stateless functions that do stuff (normally one thing) • Written in JavaScript, Swift, Python, Java, Go, PHP or Docker • JavaScript! • Can take arguments (as well as having default arguments too)
  14. 14. EXAMPLE function main() { return { output: ‘Pew pew!’ }; }
  15. 15. GETTING IT TO IBMCLOUD/OPENWHISK • CLI to create • CLI to update • (Yes, this can be repetitive) • bx wsk action create NAME file • bx wsk action update NAME file
  16. 16. DEMO
  17. 17. RUNNING YOUR ACTION • bx wsk action invoke NAME • This is asynchronous! • But you can get around that. ;)
  18. 18. DEMO
  19. 19. ACTIONS WITH ARGUMENTS • One main argument object sent to function • CLI call: • --param name value • --param-file foo.json • You can define defaults in code or at the Action level • bx wsk action update nameOfAction --param paramName paramValue
  20. 20. TASK TWO Add an argument for type 1 Use the type to figure out the color 2 Default to white 3
  21. 21. DEMO
  22. 22. MORE ON ACTIVATIONS • Useful for debugging errors • You can watch your activations live (wsk activation poll)
  23. 23. LET’S SCREW UP!
  24. 24. ASYNC ACTIONS • Wait – wasn’t it already async? • An Async action being called by an Async CLI
  25. 25. EXAMPLE function main(args) { //stuff here, fancy stuff return new Promise(function(resolve, reject) { //stuff }); }
  26. 26. TASK THREE Hit the Death Star API 1 Retrieve targeting info from XML Java-based service 2 Rewrite XML to JSON 3
  27. 27. DEMO
  28. 28. HOW DO WE ACTUALLY USE THIS?
  29. 29. ACTUALLY USING THE DARN THING • Everything has a secure REST API (and npm package) • Web Actions • API Gateway • "api-experimental“ (Old school, don’t use, deprecated, etc)
  30. 30. WEB ACTIONS • Enabled via an action annotation (think metadata) • bx wsk action update foo --web true • Your action is now anonymously-accessible via a URL • https://{APIHOST}/api/v1/web/{QUALIFIED ACTION NAME}.{EXT} • bx wsk action get NAME --url
  31. 31. WEB ACTIONS (2) • Support for HTTP, JSON, HTML, images • URL can ask for different content response types • URL can ask for a portion of the response • Automatically map query and form values to params • Access to request headers/body • Code *will* change
  32. 32. TASK FOUR Help Stormtrooper Recruitment 1 Build a static form 2 Process the form result 3
  33. 33. DEMO
  34. 34. API GATEWAY • The “Enterprise” Level API (kidding – mostly) • Enables specific HTTP methods • Enables monitoring • Enables rate limiting • Enables key/auth management • UI + CLI support
  35. 35. SEQUENCES • Simply a way to link actions • Output automatically “flows” from one to the other • Made in CLI: bx wsk action create NAME --sequence A,B,C • End result is an action • Input/Output must ‘connect’
  36. 36. TASK FIVE Create a new “Verify Type” action 1 Build Sequence between Verify and Paint 2 Return the paint color 3
  37. 37. DEMO
  38. 38. PACKAGES • Just an organization thing • Literally – a subdirectory • Actions are in a “default” package (by – wait for it – default) • CLI to create/get details on packages • Default params can be set package level • You can share packages • OpenWhisk has some (mostly around Watson stuff)
  39. 39. EXAMPLE • bx wsk package create NAME • bx wsk package list • bx wsk package get NAME (optionally with --summary) • bx wsk action create PACKAGE/ACTION foo.js
  40. 40. TRIGGERS AND RULES • A trigger is an event source • New email • New Git commit • Time based (think cron) • Triggers have data (like an event in JS) • A rule is the pairing between one trigger and one action
  41. 41. EXAMPLES • 911 Example • Blog Nag Example
  42. 42. IBM COMPOSER & CLOUD SHELL • New way to build apps • New graphical shell • https://github.com/ibm-functions/composer
  43. 43. PRICING • https://console.ng.bluemix.net/openwhisk/learn/pricing • “you only pay for the exact duration your code is executing, rounded up to the nearest 100ms” • $0.000017 per second of execution, per GB of memory allocated • 5M activations using 128MB per action and averaging 500ms: Free • 10M activations using 512MB averaging 1 second: $78.20 • Free like kittens! (Ok, so not…)
  44. 44. WRAP UP • Slack: openwhisk-team.slack.com (signup at slack.openwhisk.org) • My stuff: https://www.raymondcamden.com/tags/openwhisk • Includes an example of testing • Developer Journey: https://developer.ibm.com/code/journey/unlock-enterprise- data-using-apis/ • Visual Studio Code extension • https://github.com/openwhisk/openwhisk-vscode
  45. 45. http://www.oreilly.com/programming/free/developing-serverless- applications.csp
  46. 46. “YOU KNOW SERVERLESS STILL HAS SERVERS, RIGHT?”

×