Build a cloud native
app with OpenWhisk
@DanielKrook • Senior Software Engineer • IBM Cloud
OpenWhisk.org
@DanielKrookOpenWhisk.org
What you will learn today
• How serverless technology enables developers to write cloud
native applications better, faster, and cheaper.
• How OpenWhisk provides an open source platform to enable
these cloud native, event driven applications.
• How to get started developing with OpenWhisk on Bluemix
based on two hands on coding demos
Serverless architectures are drawing
interest due to a combination of
compelling technical and business factors
@DanielKrookOpenWhisk.org
With serverless developers focus more on code, less on infrastructure
Bare
metal
Virtual
machines
Containers
Functions
Decreasing concern (and control) over stack implementation
Increasingfocusonbusinesslogic
@DanielKrookOpenWhisk.org
Serverless platforms can address 12 Factors for developers
I Codebase Handled by developer (Manage versioning of functions themeselves)
II Dependencies Handled by developer, facilitated by serverless platform (Runtimes and packages)
III Config Handled by platform (Environment variables or injected event parameters)
IV Backing services Handled by platform (Connection information injected as event parameters)
V Build, release, run Handled by platform (Deployed resources immutable and internally versioned)
VI Processes Handled by platform (Single stateless containers used)
VII Port binding Handled by platform (Actions or functions automatically discovered)
VIII Concurrency Handled by platform (Process model hidden and scales in response to demand)
IX Disposability Handled by platform (Lifecycle hidden from user, fast startup and elastic scale prioritized)
X Dev/prod parity Handled by developer (Developer is deployer. Scope of what differs narrower)
XI Logs Handled by platform (Developer writes to console.log, platform streams logs)
XII Admin processes Handled by developer (No distinction between one off processes and long running)
@DanielKrookOpenWhisk.org
Emerging workloads are a good fit for event driven programming
Execute app logic in response to database change
Perform edge analytics in response to sensor input
Provide cognitive computing via a conversational bot
Schedule tasks according to a specific timetable
Invoke autoscaled mobile backend services
@DanielKrookOpenWhisk.org
New cost models can more accurately charge for compute time
Applications billed by compute
time (millisecond) rather than
reserved memory (GB/hour).
While many applications must still be deployed in an always on
model, serverless architectures provide an alternative that can result
in substantial cost savings for a variety of event driven workloads.
Means a greater linkage between
cloud resources used and
business operations executed.
@DanielKrookOpenWhisk.org
Technological and business factors make serverless compelling
Serverless architectures are gaining traction
Cost models getting more granular and efficient
Growth of event driven workloads that need automated scale
Platforms evolving to facilitate cloud native design for developers
@DanielKrookOpenWhisk.org
OpenWhisk enables these serverless, event-driven workloads
Serverless deployment and operations model
Optimized utilization, fine grained metering at any scale
Flexible, extensible, polyglot programming model
Open source and open ecosystem (Apache proposal)
Ability to run in public, private, and hybrid models
OpenWhisk
a cloud platform
that executes code
in response to events
The OpenWhisk
programming model
@DanielKrookOpenWhisk.org
Developers work with triggers, actions, rules, and packages
Data sources define events
they emit as Triggers.
Developers map Actions to
Triggers via Rules.
Packages provide integration
with external services.
T
A
P
R
@DanielKrookOpenWhisk.org
Triggers
A class of events that can occurT
Social events
Data changes
Device readings Location updates
User input
@DanielKrookOpenWhisk.org
Actions
Code that runs in response to an event
(that is, an event handler)
A
@DanielKrookOpenWhisk.org
Actions
Can be written in a variety of languages, such as
JavaScript, Python, Java, and Swift
A
function main(params) {
return { message: 'Hello, ' + params.name + ' from ' + params.place };
};
@DanielKrookOpenWhisk.org
Actions
Or any other language by packaging with DockerA
@DanielKrookOpenWhisk.org
Actions
Can be composed to create sequences
that increase flexibility and foster reuse
A
AA
:= A1
+ A2
+ A3
AB := A2
+ A1
+ A3
AC
:= A3
+ A1
+ A2
@DanielKrookOpenWhisk.org
Rules
An association of a trigger to an action
in a many to many mapping.
R
R := T A
@DanielKrookOpenWhisk.org
Packages
A shared collection of triggers and actionsP
A
A read
write
T changes A translate A forecast
A post
T topic
Open
Source A myAction
T myFeed
Yours
T commit
Third
Party
OpenWhisk
in action
@DanielKrookOpenWhisk.org
The OpenWhisk execution model
Pool of actions
Swift DockerJS
Trigger
1
Running
action
Running
action
Running
action
3
OpenWhisk
Engine
2 A
T
AAA
@DanielKrookOpenWhisk.org
Demo 1: Timer triggered action
Trigger
1
Running
action
2
T
A
1. Cron syntax alarm
2. Log the current time
$ wsk action create handler handler.js
$ wsk action invoke --blocking handler
$ wsk trigger create every-20-seconds 
--feed /whisk.system/alarms/alarm 
--param cron “*/20 * * * * *”
$ wsk rule create 
invoke-periodically 
every-20-seconds 
handler
$ wsk activation poll
github.com/krook/dw-openwhisk-demo-1
@DanielKrookOpenWhisk.org
OpenWhisk enables event driven applications
Event
Providers
Cloudant
GitHub
Weather
…
Which triggers execution of
associated OpenWhisk action
2
Slack
JS Swift Docker …
An event occurs, for example
• Commit pushed to GitHub repository
• Data changed in Cloudant
1
OpenWhisk
@DanielKrookOpenWhisk.org
OpenWhisk can implement REST microservices
Send HTTP request
HTTP GET
app.com/customers
1
Invoke OpenWhisk
action get-customers
Browser
Mobile App
Web App
2
JS Swift Docker …
OpenWhisk
API
Proxy
@DanielKrookOpenWhisk.org
Demo 2: Polyglot applications with data triggers
github.com/krook/dw-openwhisk-demo-2
Trigger
2
JavaScript
action
3
T
A
1. Image uploaded to Cloudant
3. JavaScript action parses image
metadata and transforms image
Docker
action
4 A
incoming
checks
processed
checks
5
1
2. Trigger fired in OpenWhisk
4. Docker action parses image with OCR
5. Extracted info stored back to Cloudant
OpenWhisk
@DanielKrookOpenWhisk.org
More examples: Smart home IoT, mobile banking
github.com/openwhisk/awesome-openwhisk
Project OpenFridge:
Improving customer service
with event driven IoT
Project OpenChecks
Summary
@DanielKrookOpenWhisk.org
What you learned today
• We’re in the early days of an evolution that is empowering developers
to write cloud native applications better, faster, and cheaper
• OpenWhisk provides an open source platform to enable cloud native,
serverless, event driven applications
• Bluemix provides a hosted instance of OpenWhisk that you can use
to get started (and offers integration with a catalog of services)
@DanielKrookOpenWhisk.org
Try OpenWhisk in hosted on IBM Bluemix
bluemix.net
@DanielKrookOpenWhisk.org
Join us to build a cloud native platform for the future!
OpenWhisk.org

Build a cloud native app with OpenWhisk

  • 1.
    Build a cloudnative app with OpenWhisk @DanielKrook • Senior Software Engineer • IBM Cloud OpenWhisk.org
  • 2.
    @DanielKrookOpenWhisk.org What you willlearn today • How serverless technology enables developers to write cloud native applications better, faster, and cheaper. • How OpenWhisk provides an open source platform to enable these cloud native, event driven applications. • How to get started developing with OpenWhisk on Bluemix based on two hands on coding demos
  • 3.
    Serverless architectures aredrawing interest due to a combination of compelling technical and business factors
  • 4.
    @DanielKrookOpenWhisk.org With serverless developersfocus more on code, less on infrastructure Bare metal Virtual machines Containers Functions Decreasing concern (and control) over stack implementation Increasingfocusonbusinesslogic
  • 5.
    @DanielKrookOpenWhisk.org Serverless platforms canaddress 12 Factors for developers I Codebase Handled by developer (Manage versioning of functions themeselves) II Dependencies Handled by developer, facilitated by serverless platform (Runtimes and packages) III Config Handled by platform (Environment variables or injected event parameters) IV Backing services Handled by platform (Connection information injected as event parameters) V Build, release, run Handled by platform (Deployed resources immutable and internally versioned) VI Processes Handled by platform (Single stateless containers used) VII Port binding Handled by platform (Actions or functions automatically discovered) VIII Concurrency Handled by platform (Process model hidden and scales in response to demand) IX Disposability Handled by platform (Lifecycle hidden from user, fast startup and elastic scale prioritized) X Dev/prod parity Handled by developer (Developer is deployer. Scope of what differs narrower) XI Logs Handled by platform (Developer writes to console.log, platform streams logs) XII Admin processes Handled by developer (No distinction between one off processes and long running)
  • 6.
    @DanielKrookOpenWhisk.org Emerging workloads area good fit for event driven programming Execute app logic in response to database change Perform edge analytics in response to sensor input Provide cognitive computing via a conversational bot Schedule tasks according to a specific timetable Invoke autoscaled mobile backend services
  • 7.
    @DanielKrookOpenWhisk.org New cost modelscan more accurately charge for compute time Applications billed by compute time (millisecond) rather than reserved memory (GB/hour). While many applications must still be deployed in an always on model, serverless architectures provide an alternative that can result in substantial cost savings for a variety of event driven workloads. Means a greater linkage between cloud resources used and business operations executed.
  • 8.
    @DanielKrookOpenWhisk.org Technological and businessfactors make serverless compelling Serverless architectures are gaining traction Cost models getting more granular and efficient Growth of event driven workloads that need automated scale Platforms evolving to facilitate cloud native design for developers
  • 9.
    @DanielKrookOpenWhisk.org OpenWhisk enables theseserverless, event-driven workloads Serverless deployment and operations model Optimized utilization, fine grained metering at any scale Flexible, extensible, polyglot programming model Open source and open ecosystem (Apache proposal) Ability to run in public, private, and hybrid models OpenWhisk a cloud platform that executes code in response to events
  • 10.
  • 11.
    @DanielKrookOpenWhisk.org Developers work withtriggers, actions, rules, and packages Data sources define events they emit as Triggers. Developers map Actions to Triggers via Rules. Packages provide integration with external services. T A P R
  • 12.
    @DanielKrookOpenWhisk.org Triggers A class ofevents that can occurT Social events Data changes Device readings Location updates User input
  • 13.
    @DanielKrookOpenWhisk.org Actions Code that runsin response to an event (that is, an event handler) A
  • 14.
    @DanielKrookOpenWhisk.org Actions Can be writtenin a variety of languages, such as JavaScript, Python, Java, and Swift A function main(params) { return { message: 'Hello, ' + params.name + ' from ' + params.place }; };
  • 15.
    @DanielKrookOpenWhisk.org Actions Or any otherlanguage by packaging with DockerA
  • 16.
    @DanielKrookOpenWhisk.org Actions Can be composedto create sequences that increase flexibility and foster reuse A AA := A1 + A2 + A3 AB := A2 + A1 + A3 AC := A3 + A1 + A2
  • 17.
    @DanielKrookOpenWhisk.org Rules An association ofa trigger to an action in a many to many mapping. R R := T A
  • 18.
    @DanielKrookOpenWhisk.org Packages A shared collectionof triggers and actionsP A A read write T changes A translate A forecast A post T topic Open Source A myAction T myFeed Yours T commit Third Party
  • 19.
  • 20.
    @DanielKrookOpenWhisk.org The OpenWhisk executionmodel Pool of actions Swift DockerJS Trigger 1 Running action Running action Running action 3 OpenWhisk Engine 2 A T AAA
  • 21.
    @DanielKrookOpenWhisk.org Demo 1: Timertriggered action Trigger 1 Running action 2 T A 1. Cron syntax alarm 2. Log the current time $ wsk action create handler handler.js $ wsk action invoke --blocking handler $ wsk trigger create every-20-seconds --feed /whisk.system/alarms/alarm --param cron “*/20 * * * * *” $ wsk rule create invoke-periodically every-20-seconds handler $ wsk activation poll github.com/krook/dw-openwhisk-demo-1
  • 22.
    @DanielKrookOpenWhisk.org OpenWhisk enables eventdriven applications Event Providers Cloudant GitHub Weather … Which triggers execution of associated OpenWhisk action 2 Slack JS Swift Docker … An event occurs, for example • Commit pushed to GitHub repository • Data changed in Cloudant 1 OpenWhisk
  • 23.
    @DanielKrookOpenWhisk.org OpenWhisk can implementREST microservices Send HTTP request HTTP GET app.com/customers 1 Invoke OpenWhisk action get-customers Browser Mobile App Web App 2 JS Swift Docker … OpenWhisk API Proxy
  • 24.
    @DanielKrookOpenWhisk.org Demo 2: Polyglotapplications with data triggers github.com/krook/dw-openwhisk-demo-2 Trigger 2 JavaScript action 3 T A 1. Image uploaded to Cloudant 3. JavaScript action parses image metadata and transforms image Docker action 4 A incoming checks processed checks 5 1 2. Trigger fired in OpenWhisk 4. Docker action parses image with OCR 5. Extracted info stored back to Cloudant OpenWhisk
  • 25.
    @DanielKrookOpenWhisk.org More examples: Smarthome IoT, mobile banking github.com/openwhisk/awesome-openwhisk Project OpenFridge: Improving customer service with event driven IoT Project OpenChecks
  • 26.
  • 27.
    @DanielKrookOpenWhisk.org What you learnedtoday • We’re in the early days of an evolution that is empowering developers to write cloud native applications better, faster, and cheaper • OpenWhisk provides an open source platform to enable cloud native, serverless, event driven applications • Bluemix provides a hosted instance of OpenWhisk that you can use to get started (and offers integration with a catalog of services)
  • 28.
    @DanielKrookOpenWhisk.org Try OpenWhisk inhosted on IBM Bluemix bluemix.net
  • 29.
    @DanielKrookOpenWhisk.org Join us tobuild a cloud native platform for the future! OpenWhisk.org