SlideShare a Scribd company logo
Building serverless application on the Apache Openwhisk platform
Lucio Grenzi
CODEMOTION MILAN - SPECIAL
EDITION 10 – 11 NOVEMBER 2017
Who am I?
●
Developer, consultant, speaker
l.grenzi@gmail.com
dogwolf
lucio.grenzi
Agenda
●
What is servless computing?
●
Introduction to Apache OpenWhisk
●
Deployment models
Another serverless talk?
https://www.flickr.com/photos/vicki_burton/7421502022
The evolution
Bare Metal VMs Containers Functions
https://www.flickr.com/photos/nomeacuerdo/3108955591/
Serverless: the pros
●
Simple but usable primitives
●
Pay only usage
●
Scale with usage
●
Built in availability & fault tolerance
Serverless: the cons
●
Latency
●
Async
●
No way to keep connection open
●
Configuration is a challenge
●
Rethink of the common practices
Apache OpenWhisk
Apache OpenWhisk is a serverless, open source cloud platform
that allows you to execute code in response to events at any scale.
OpenWhisk handles the infrastructure and servers so you can
focus on building amazing things.
- http://openwhisk.incubator.apache.org/about.html -
Supporters
High-Level Programming Model
The internal flow of processing
Enable the environment
●
Vagrant
●
Native: Ubuntu or MacOs
●
Commercial support: IBM BlueMix
Manage the system
OpenWhisk offer:
●
Command line interface to mangare all the aspect of the system
IBM BlueMix offer:
●
Graphic editor
Activate the CLI
There are two required properties to configure in order to use the CLI:
●
API host (name or IP address) for the OpenWhisk deployment you
want to use.
●
Authorization key (username and password) which grants you access
to the OpenWhisk API.
./bin/wsk property set --apihost <openwhisk_baseurl>
./bin/wsk property set --auth `auth.guest`
wskadmin
Tool to generate a new namespace and authentication, manage
application servers as well as the configuration, application
deployment, and server runtime operations.
It can provide below functions:
●
management for users and limitations
●
query of db and system log
Actions
●
Actions are stateless code snippets that run on the OpenWhisk
●
Can be explicitly invoked, or run in response to an event
●
The result of an action are a dictionary of key-value pairs
Triggers
●
Let you specify outside sources as a way to kick off an action
●
Can be fired by using a dictionary of key-value pairs
●
Can be explicitly fired by a user or by an external event source
Rules
●
Allow actions to react to the events
●
Associates one trigger with one action
●
Can be explicitly fired by a user or by an external event source
Show me the code 1/2
/**
* main() will be invoked when you Run This Action
* @param OpenWhisk actions accept a single parameter, which must be a JSON object.
* @return The output of this action, which must be a JSON object.
*/
const request = require('request-promise');
function main(params) {
return request({
url: "http://myhost.mybluemix.net/myexp",
method: "POST",
headers: {"Content-Type": "text/plain"}
}).then(response => {
if(response.success) {
return Promise.resolved({message: "nice"});
} else {
return Promise.rejected({error: "it broke"});
} }); }
Show me the code 2/2
$ wsk trigger create trgexample
ok: created trigger trgeample
$ wsk action create actexample index.js
ok: created action actexample
$ wsk rule create rulexample trgexample actexmple
ok: created rule rulexample
$wsk action invoke actexample--blocking --result main
curl -u "yourUserName":"yourPassword" -H "Content-Type: application/json" -X POST
https://MyIPAddress/api/v1/namespaces/myaccount/actions/actexample/main?
blocking=true
Packages
●
It's a combination of other actions/triggers/rules that you can
link to your own stuff
●
Can include actions and feeds.
– Actions: a piece of code that runs on OpenWhisk
– Feeds: configure external event or fire trigger event
Browsing packages
$ wsk package list /whisk.system
packages
/whisk.system/cloudant shared
/whisk.system/alarms shared
/whisk.system/websocket shared
/whisk.system/system shared
/whisk.system/utils shared
/whisk.system/slack shared
/whisk.system/samples shared
/whisk.system/github shared
/whisk.system/pushnotifications
$ wsk package get --summary /whisk.system/github
Rest APIs
https://{APIHOST}/api/v1/namespaces/{namespace}
https://{APIHOST}/api/v1/namespaces/{namespace}/actions/[{packageName}/]{actionName}
https://{APIHOST}/api/v1/namespaces/{namespace}/triggers/{triggerName}
https://{APIHOST}/api/v1/namespaces/{namespace}/rules/{ruleName}
https://{APIHOST}/api/v1/namespaces/{namespace}/packages/{packageName}
https://{APIHOST}/api/v1/namespaces/{namespace}/activations/{activationName}
All the capabilities in the system are available through a REST API
All APIs are protected with HTTP Basic authentication
Alarm scheduler
$ wsk trigger create periodic --feed /whisk.system/alarms/alarm -p cron '* * * * * *'
-p trigger_payload '{"hi":"codemotion"}'
ok: invoked /whisk.system/alarms/alarm with id 13fc55adb...
...
ok: created trigger feed periodic
Alarm loop
function calculateSchedule() {
const now = new Date()
const seconds = now.getSeconds()
const nextMinute = (now.getMinutes() + 1) % 60
return `${seconds} ${nextMinute} * * * *`
}
function main(params) {
const ow = openwhisk();
const params = {cron: calculateSchedule(), maxTriggers: 1}
console.log(params)
return ow.feeds.delete({name: '/whisk.system/alarms/alarm', trigger: 'delay'}).then(() => {
console.log('delay trigger feed deleted.')
return ow.feeds.create({name: '/whisk.system/alarms/alarm', trigger: 'delay',
params: params}) }).then(result => {
console.log('delay trigger feed created.')
}).catch(err => {
console.error('failed to create/delete delay trigger', err)
console.log("ERROR", err.error.response.result) }) }
Alarm loop
$ wsk action create reschedule reschedule.js
ok: created action reschedule
Create an action
$ wsk trigger create delay --feed /whisk.system/alarms/alarm -p cron '* * * * * *'
ok: invoked /whisk.system/alarms/alarm with id b3da4de5726b4...
...
ok: created trigger delay
Create a trigger
$ wsk rule create reschedule_delay delay reschedule
ok: created rule reschedule_delay
Create a rule that connect the action with the rule
Develop and deploy
●
OpenWhisk
– Wrapper around the OpenWhisk API
– $ npm install openwhisk
●
Serverless
– Framework
– Provider agnostic
– $ npm install serverless -g
Serverless Openwhisk start
●
Nodejs > 6.5.0
●
$ npm install --global serverless serverless-openwhisk
●
$ serverless create --template openwhisk-nodejs --path my-path
●
$ serverless deploy
Anatomy of Serverless.yml
Demo
Serverless Openwhisk package
●
Nodejs > 6.5.0
●
$ npm install --global serverless serverless-openwhisk
●
$ serverless package --package my-package
●
$ serverless deploy
Do practice
https://github.com/apache/incubator-openwhisk-workshop
Nodejs >= 6 required
Installation
$ npm install -g openwhisk-workshop
Usage
$ openwhisk-workshop
Resources
●
https://serverless.com/
●
http://openwhisk.incubator.apache.org/
●
https://medium.com/openwhisk/advanced-openwhisk-alarm-schedule
●
https://www.raymondcamden.com/2017/01/31/using-packages-in-op
Questions?
https://www.flickr.com/photos/derek_b/3046770021/
https://www.flickr.com/photos/wwworks/4759535950/

More Related Content

PDF
Callbacks and control flow in Node js
PPTX
Avoiding Callback Hell with Async.js
PPTX
Avoiding callback hell in Node js using promises
PPTX
Bucks County Tech Meetup: node.js introduction
PDF
Callbacks, promises, generators - asynchronous javascript
PDF
Asynchronous programming done right - Node.js
PDF
Asynchronní programování
KEY
Introduction to node.js
Callbacks and control flow in Node js
Avoiding Callback Hell with Async.js
Avoiding callback hell in Node js using promises
Bucks County Tech Meetup: node.js introduction
Callbacks, promises, generators - asynchronous javascript
Asynchronous programming done right - Node.js
Asynchronní programování
Introduction to node.js

What's hot (20)

PPTX
Behind modern concurrency primitives
PPTX
Akka.NET streams and reactive streams
PDF
Asynchronous Programming FTW! 2 (with AnyEvent)
PPTX
Async Programming with C#5: Basics and Pitfalls
PPTX
All you need to know about the JavaScript event loop
PDF
How to send gzipped requests with boto3
PDF
Nestjs MasterClass Slides
PPTX
Reactive Java (33rd Degree)
PDF
Grunt.js introduction
ODP
Introduce about Nodejs - duyetdev.com
PDF
End to end todo list app with NestJs - Angular - Redux & Redux Saga
PDF
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
PDF
State management in a GraphQL era
PPTX
Zeromq - Pycon India 2013
PPTX
Understanding reactive programming with microsoft reactive extensions
PPTX
Correcting Common Async/Await Mistakes in .NET
PDF
Martin Anderson - threads v actors
PPTX
Introduction to Service Workers | Matteo Manchi
PPTX
Async Best Practices
PDF
Retrofit
Behind modern concurrency primitives
Akka.NET streams and reactive streams
Asynchronous Programming FTW! 2 (with AnyEvent)
Async Programming with C#5: Basics and Pitfalls
All you need to know about the JavaScript event loop
How to send gzipped requests with boto3
Nestjs MasterClass Slides
Reactive Java (33rd Degree)
Grunt.js introduction
Introduce about Nodejs - duyetdev.com
End to end todo list app with NestJs - Angular - Redux & Redux Saga
Introducing Middy, Node.js middleware engine for AWS Lambda (FrontConf Munich...
State management in a GraphQL era
Zeromq - Pycon India 2013
Understanding reactive programming with microsoft reactive extensions
Correcting Common Async/Await Mistakes in .NET
Martin Anderson - threads v actors
Introduction to Service Workers | Matteo Manchi
Async Best Practices
Retrofit
Ad

Similar to Building serverless application on the Apache Openwhisk platform (20)

PDF
Serverless apps with OpenWhisk
PDF
Build a cloud native app with OpenWhisk
PPTX
Serverless Apps with Open Whisk
PDF
Going Serverless with OpenWhisk
PDF
OpenWhisk - Serverless Architecture
PDF
OpenWhisk Under the Hood -- London Oct 16 2016
PPT
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
PDF
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
PPTX
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...
PDF
OpenWhisk Lab
PDF
OpenWhisk - A platform for cloud native, serverless, event driven apps
PDF
Your Java Journey into the Serverless World
PPTX
Serverless meetup - OpenWhisk overview and architecture
PDF
Andreas Nauerz and Michael Behrendt - Event Driven and Serverless Programming...
PDF
Serverless forwardjs
PDF
How to build a Distributed Serverless Polyglot Microservices IoT Platform us...
PPTX
PDF
Openwhisk - Colorado Meetups
PPT
IBM Bluemix OpenWhisk: Interconnect 2016, Las Vegas: CCD-1088: The Future of ...
PPT
IBM Bluemix Openwhisk
Serverless apps with OpenWhisk
Build a cloud native app with OpenWhisk
Serverless Apps with Open Whisk
Going Serverless with OpenWhisk
OpenWhisk - Serverless Architecture
OpenWhisk Under the Hood -- London Oct 16 2016
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
IBM Bluemix OpenWhisk: Cloud Foundry Summit 2016, Frankfurt, Germany: The Fut...
OpenWhisk Lab
OpenWhisk - A platform for cloud native, serverless, event driven apps
Your Java Journey into the Serverless World
Serverless meetup - OpenWhisk overview and architecture
Andreas Nauerz and Michael Behrendt - Event Driven and Serverless Programming...
Serverless forwardjs
How to build a Distributed Serverless Polyglot Microservices IoT Platform us...
Openwhisk - Colorado Meetups
IBM Bluemix OpenWhisk: Interconnect 2016, Las Vegas: CCD-1088: The Future of ...
IBM Bluemix Openwhisk
Ad

More from Lucio Grenzi (13)

ODP
How to use Postgresql in order to handle Prometheus metrics storage
ODP
Patroni: PostgreSQL HA in the cloud
ODP
Postgrest: the REST API for PostgreSQL databases
PPTX
Full slidescr16
ODP
Use Ionic Framework to develop mobile application
ODP
Rabbitmq & Postgresql
ODP
Jenkins djangovillage
ODP
Geodjango and HTML 5
ODP
PLV8 - The PostgreSQL web side
ODP
Pg tap
PPT
Geodjango
PPT
Yui app-framework
PPT
node.js e Postgresql
How to use Postgresql in order to handle Prometheus metrics storage
Patroni: PostgreSQL HA in the cloud
Postgrest: the REST API for PostgreSQL databases
Full slidescr16
Use Ionic Framework to develop mobile application
Rabbitmq & Postgresql
Jenkins djangovillage
Geodjango and HTML 5
PLV8 - The PostgreSQL web side
Pg tap
Geodjango
Yui app-framework
node.js e Postgresql

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Cloud computing and distributed systems.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Cloud computing and distributed systems.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Building serverless application on the Apache Openwhisk platform