GOING SERVERLESS WITH
OPENWHISK
RAYMOND CAMDEN
WHY AM I HERE?
• Developer Advocate for IBM
• LoopBack, OpenWhisk, Node.js,
Cordova, web stuff, and cats
• Blogging at
raymondcamden.com
• Tweeting at @raymondcamden
CONGRATULATIONS!
• New job!
• CTO of the Galactic Empire
• Full discretion!
• Build the Future of the Empire!
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
NEW SYSTEM
• Node/JavaScript
• Microservices
• Serverless
LETS TALK ABOUT THAT NAME…
“Serverless”
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
“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”
APACHE OPENWHISK (OPENWHISK.ORG)
INSTALLATION
• Focused on the IBM Cloud (Bluemix) path
• https://console.ng.bluemix.net/openwhisk/
TASK ONE
Stormtroopers
get armor
1
Armor needs
paint
2
What color
should it be?
3
ACTIONS!
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)
EXAMPLE
function main() {
return { output: ‘Pew pew!’ };
}
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
DEMO
RUNNING YOUR ACTION
• bx wsk action invoke NAME
• This is asynchronous!
• But you can get around that. ;)
DEMO
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
TASK TWO
Add an argument
for type
1
Use the type to
figure out the
color
2
Default to white
3
DEMO
MORE ON ACTIVATIONS
• Useful for debugging errors
• You can watch your activations live (wsk activation poll)
LET’S SCREW UP!
ASYNC ACTIONS
• Wait – wasn’t it already async?
• An Async action being called by an Async CLI
EXAMPLE
function main(args) {
//stuff here, fancy stuff
return new Promise(function(resolve, reject) {
//stuff
});
}
TASK THREE
Hit the Death Star
API
1
Retrieve targeting
info from XML
Java-based service
2
Rewrite XML to
JSON
3
DEMO
HOW DO WE ACTUALLY USE
THIS?
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)
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
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
TASK FOUR
Help
Stormtrooper
Recruitment
1
Build a static form
2
Process the form
result
3
DEMO
API GATEWAY
• The “Enterprise” Level API (kidding – mostly)
• Enables specific HTTP methods
• Enables monitoring
• Enables rate limiting
• Enables key/auth management
• UI + CLI support
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’
TASK FIVE
Create a new
“Verify Type”
action
1
Build Sequence
between Verify
and Paint
2
Return the paint
color
3
DEMO
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)
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
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
EXAMPLES
• 911 Example
• Blog Nag Example
IBM COMPOSER & CLOUD SHELL
• New way to build apps
• New graphical shell
• https://github.com/ibm-functions/composer
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…)
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
http://www.oreilly.com/programming/free/developing-serverless-
applications.csp
“YOU KNOW SERVERLESS
STILL HAS SERVERS,
RIGHT?”
Going Serverless with OpenWhisk

Going Serverless with OpenWhisk

  • 1.
  • 2.
    WHY AM IHERE? • Developer Advocate for IBM • LoopBack, OpenWhisk, Node.js, Cordova, web stuff, and cats • Blogging at raymondcamden.com • Tweeting at @raymondcamden
  • 7.
    CONGRATULATIONS! • New job! •CTO of the Galactic Empire • Full discretion! • Build the Future of the Empire!
  • 9.
    CURRENT SYSTEM • J2EEservers • 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
  • 10.
    NEW SYSTEM • Node/JavaScript •Microservices • Serverless
  • 11.
    LETS TALK ABOUTTHAT NAME… “Serverless”
  • 12.
    WHAT IS SERVERLESS? “Serverlesscomputing 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
  • 14.
    “FUNCTION AS ASERVICE” • 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”
  • 18.
  • 20.
    INSTALLATION • Focused onthe IBM Cloud (Bluemix) path • https://console.ng.bluemix.net/openwhisk/
  • 24.
    TASK ONE Stormtroopers get armor 1 Armorneeds paint 2 What color should it be? 3
  • 25.
  • 26.
    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)
  • 27.
    EXAMPLE function main() { return{ output: ‘Pew pew!’ }; }
  • 28.
    GETTING IT TOIBMCLOUD/OPENWHISK • CLI to create • CLI to update • (Yes, this can be repetitive) • bx wsk action create NAME file • bx wsk action update NAME file
  • 29.
  • 30.
    RUNNING YOUR ACTION •bx wsk action invoke NAME • This is asynchronous! • But you can get around that. ;)
  • 31.
  • 32.
    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
  • 33.
    TASK TWO Add anargument for type 1 Use the type to figure out the color 2 Default to white 3
  • 34.
  • 35.
    MORE ON ACTIVATIONS •Useful for debugging errors • You can watch your activations live (wsk activation poll)
  • 36.
  • 37.
    ASYNC ACTIONS • Wait– wasn’t it already async? • An Async action being called by an Async CLI
  • 38.
    EXAMPLE function main(args) { //stuffhere, fancy stuff return new Promise(function(resolve, reject) { //stuff }); }
  • 39.
    TASK THREE Hit theDeath Star API 1 Retrieve targeting info from XML Java-based service 2 Rewrite XML to JSON 3
  • 40.
  • 41.
    HOW DO WEACTUALLY USE THIS?
  • 42.
    ACTUALLY USING THEDARN THING • Everything has a secure REST API (and npm package) • Web Actions • API Gateway • "api-experimental“ (Old school, don’t use, deprecated, etc)
  • 43.
    WEB ACTIONS • Enabledvia 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
  • 44.
    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
  • 45.
    TASK FOUR Help Stormtrooper Recruitment 1 Build astatic form 2 Process the form result 3
  • 46.
  • 47.
    API GATEWAY • The“Enterprise” Level API (kidding – mostly) • Enables specific HTTP methods • Enables monitoring • Enables rate limiting • Enables key/auth management • UI + CLI support
  • 48.
    SEQUENCES • Simply away 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’
  • 49.
    TASK FIVE Create anew “Verify Type” action 1 Build Sequence between Verify and Paint 2 Return the paint color 3
  • 50.
  • 51.
    PACKAGES • Just anorganization 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)
  • 52.
    EXAMPLE • bx wskpackage create NAME • bx wsk package list • bx wsk package get NAME (optionally with --summary) • bx wsk action create PACKAGE/ACTION foo.js
  • 53.
    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
  • 54.
  • 55.
    IBM COMPOSER &CLOUD SHELL • New way to build apps • New graphical shell • https://github.com/ibm-functions/composer
  • 59.
    PRICING • https://console.ng.bluemix.net/openwhisk/learn/pricing • “youonly 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…)
  • 60.
    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
  • 61.
  • 62.
    “YOU KNOW SERVERLESS STILLHAS SERVERS, RIGHT?”

Editor's Notes

  • #12 I want to start off talking about “serverless”
  • #30 Create the action, make the name dynamic Update List
  • #32 Wsk action invoke name Wsk activation get X Wsk action invoke name –b Wsk action invoke name –b –r
  • #48 README! Be sure to run wsk bluemix login --user X --password Pick an action, let's say hello2 First, make it a web action! wsk action update hello2 --web true Now make a managed API: wsk api create /apis /hello2 get hello2 Note the output - it's the URL. Mention you can wsk api list if you forget copy the url, paste into browser, done, maybe add ?name=ray