Serverless Computing with Apache OpenWhisk

A presentation at Apache EU Roadshow in June 2018 in Berlin, Germany by Lorna Jane Mitchell

Slide 1

Slide 1

Serverless Computing with Apache OpenWhisk   Lorna Mitchell, IBM

Slide 2

Slide 2

What is Serverless? • Code snippet • Deployed to cloud • Executed in response to an event • Scaled on demand • Costs nothing when idle @lornajane

Slide 3

Slide 3

Where are the Servers? The servers are alive and well.     (your function gets containerised, OpenWhisk grabs and runs it on demand in response to the registered triggers) @lornajane

Slide 4

Slide 4

Does Serverless Solve Real Problems? @lornajane

Slide 5

Slide 5

Does Serverless Solve Real Problems? Yes! * @lornajane

Slide 6

Slide 6

Does Serverless Solve Real Problems? Yes! * * maybe not all of them @lornajane

Slide 7

Slide 7

APIs and Microservices Serverless is a great fit for Microservices!   Each endpoint (URL and verb combination) is a serverless action   An API Gateway maps routes to actions   Each endpoint is independent @lornajane

Slide 8

Slide 8

One-Off Endpoints No need to spin up a whole server just for your: • Alexa skill • mailing list/slack team signup • incoming webhook from GitHub/Twilio/Nexmo/Zapier @lornajane

Slide 9

Slide 9

Just Enough Backend Code Mobile and frontend experts often need some server-side code for APIs or secure Auth   No sysadmin skills required @lornajane

Slide 10

Slide 10

Serverless and Data When data is atomic, there's so much we can do with our easy-entry, highly scalable serverless platforms. • Transform data • React to database changes or incoming data • Work with small volume, trickling data • Work with high volume, streaming data • Handle one-off data transformation or import @lornajane

Slide 11

Slide 11

Meet Apache OpenWhisk   @lornajane

Slide 12

Slide 12

Meet Apache OpenWhisk • http://openwhisk.incubator.apache.org/ • Currently an incubator project, working towards graduation • Contributors from a variety of backgrounds   @lornajane

Slide 13

Slide 13

Supported Technologies OpenWhisk is Open Source and extensible. It supports: • Java • NodeJS • PHP • Python • Swift   Docker containers can also be deployed and run. @lornajane

Slide 14

Slide 14

Getting Started With Apache OpenWhisk @lornajane

Slide 15

Slide 15

OpenWhisk Vocabulary • trigger an event, such as an incoming HTTP request • rule map a trigger to an action • action a function, optionally with parameters • package collect actions and parameters together • sequence more than one action in a row • cold start time to run a fresh action @lornajane

Slide 16

Slide 16

Hello World in JS A main function, with a single parameter: exports . main

=

function ( args )

{

return ({ "body" :

"Hello, World!" }); };   Function must return an object or a Promise @lornajane

Slide 17

Slide 17

Parameters Parameters can be set: • at deploy time • at run time (including by the events that trigger them)   CNCF project to standardise event params: https://github.com/cloudevents/spec @lornajane

Slide 18

Slide 18

Deploying to OpenWhisk Deploy code: wsk package update demo zip hello.zip index.js wsk action update --kind nodejs:6 demo/hello1 hello.zip   Then run it: wsk action invoke --result demo/hello1 @lornajane

Slide 19

Slide 19

Web-Enabled Actions Deploy code: wsk package update demo zip hello.zip index.js wsk action update --kind nodejs:6 --web true demo/hello1 hello.zip   Then get the URL and curl it: wsk action get --url demo/hello1 curl https://172.17.0.1/api/v1/web/guest/demo/hello1 @lornajane

Slide 20

Slide 20

More About Packages Packages allow us to: • group actions together • set parameters on packages, used by all actions   Sequences can include actions from other packages @lornajane

Slide 21

Slide 21

Built In Packages There are some packages and actions available by default: • utils • cloudant • github • slack • websocket • samples @lornajane

Slide 22

Slide 22

Using Built-In Actions As an example: there's a wordCount action in the samples package: wsk -i action invoke --result /whisk.system/samples/wordCount
-p payload "A good way to ruin a fine walk"   Returns: 8 @lornajane

Slide 23

Slide 23

Using Sequences For example: notify Slack when a user registers @lornajane

Slide 24

Slide 24

Serverless and Apache OpenWhisk @lornajane

Slide 25

Slide 25

Resources • http://openwhisk.incubator.apache.org/ • https://www.ibm.com/cloud/functions • https://lornajane.net   For more: "Serverless Microservices are the New Black" tomorrow afternoon @lornajane