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/addtoimc",
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
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
ODP
Trac Project And Process Management For Developers And Sys Admins Presentation
PDF
Bulding a reactive game engine with Spring 5 & Couchbase
PDF
Presentation security automation (Selenium Camp)
PPTX
Dan Persa, Maximilian Fellner - The recipe for scalable frontends - Codemotio...
PDF
Building a serverless company on AWS lambda and Serverless framework
PDF
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
PDF
Composable and streamable Play apps
Cracking JWT tokens: a tale of magic, Node.JS and parallel computing
Trac Project And Process Management For Developers And Sys Admins Presentation
Bulding a reactive game engine with Spring 5 & Couchbase
Presentation security automation (Selenium Camp)
Dan Persa, Maximilian Fellner - The recipe for scalable frontends - Codemotio...
Building a serverless company on AWS lambda and Serverless framework
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Composable and streamable Play apps

What's hot (20)

PDF
Security Checkpoints in Agile SDLC
PDF
DAST в CI/CD, Ольга Свиридова
PDF
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
PDF
We Are All Testers Now: The Testing Pyramid and Front-End Development
PPTX
Full stack development with node and NoSQL - All Things Open - October 2017
PDF
Container and microservices: a love story
PDF
Regex Considered Harmful: Use Rosie Pattern Language Instead
PDF
vienna.js - Automatic testing of (RESTful) API documentation
PPTX
Introduction to Node js
PDF
Node.js vs Play Framework (with Japanese subtitles)
PDF
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
PDF
Microservices in Scala: Play Framework
PPTX
Real world functional reactive programming
PPTX
OWASP ZAP Workshop for QA Testers
PDF
React Development with the MERN Stack
PPTX
Dropwizard Introduction
PDF
Serverless Java on Kubernetes
PDF
The Many Ways to Test Your React App
PDF
Play Framework: async I/O with Java and Scala
PDF
Everything as a code
Security Checkpoints in Agile SDLC
DAST в CI/CD, Ольга Свиридова
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
We Are All Testers Now: The Testing Pyramid and Front-End Development
Full stack development with node and NoSQL - All Things Open - October 2017
Container and microservices: a love story
Regex Considered Harmful: Use Rosie Pattern Language Instead
vienna.js - Automatic testing of (RESTful) API documentation
Introduction to Node js
Node.js vs Play Framework (with Japanese subtitles)
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
Microservices in Scala: Play Framework
Real world functional reactive programming
OWASP ZAP Workshop for QA Testers
React Development with the MERN Stack
Dropwizard Introduction
Serverless Java on Kubernetes
The Many Ways to Test Your React App
Play Framework: async I/O with Java and Scala
Everything as a code
Ad

Viewers also liked (20)

PDF
Brian Ketelsen - Microservices in Go using Micro - Codemotion Milan 2017
PDF
Thomas Rossetto - Container and microservices: a love story - Codemotion Mila...
PPSX
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
PDF
Marco Balduzzi - Cyber-crime and attacks in the dark side of the web - Codemo...
PDF
The Most Important Thing - Mike Lee - Codemotion Amsterdam 2017
PPTX
Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...
PPTX
How to build an HA container orchestrator infrastructure for production – Giu...
PDF
Lorenzo Barbieri - Serverless computing in Azure: Functions, Logic Apps and m...
PDF
Fabrizio Cornelli - Antropologia di un Dev(Sec)Ops secondo il modello Hunter ...
PPTX
Francesco Arcieri - La monetizzazione delle API - Codemotion Milan 2017
PDF
Mobile UX for user engagement and monetization - Emilia Ciardi - Codemotion R...
PDF
Valentina Mazzoni - GDG Italia Meetup - Codemotion Milan 2017
PPTX
Dark patterns and mobile UX design - Emilia Ciardi - Codemotion Amsterdam 2017
PDF
Yan Cui - Serverless in production, an experience report - Codemotion Milan 2017
PDF
Andrea Maietta - Il fascino della supercazzola: un breve viaggio nel mondo de...
PPTX
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...
PDF
Luciano Fiandesio - Docker 101 | Codemotion Milan 2015
PDF
From Doctor to Coder: A Whole New World? - Aisha Sie - Codemotion Amsterdam 2017
PDF
Alison B Lowndes - Fueling the Artificial Intelligence Revolution with Gaming...
PDF
Webinar: Mario Cartia - Facciamo il Punto su Presente e Futuro dei framework ...
Brian Ketelsen - Microservices in Go using Micro - Codemotion Milan 2017
Thomas Rossetto - Container and microservices: a love story - Codemotion Mila...
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
Marco Balduzzi - Cyber-crime and attacks in the dark side of the web - Codemo...
The Most Important Thing - Mike Lee - Codemotion Amsterdam 2017
Building multi lingual and empatic bots - Sander van den Hoven - Codemotion A...
How to build an HA container orchestrator infrastructure for production – Giu...
Lorenzo Barbieri - Serverless computing in Azure: Functions, Logic Apps and m...
Fabrizio Cornelli - Antropologia di un Dev(Sec)Ops secondo il modello Hunter ...
Francesco Arcieri - La monetizzazione delle API - Codemotion Milan 2017
Mobile UX for user engagement and monetization - Emilia Ciardi - Codemotion R...
Valentina Mazzoni - GDG Italia Meetup - Codemotion Milan 2017
Dark patterns and mobile UX design - Emilia Ciardi - Codemotion Amsterdam 2017
Yan Cui - Serverless in production, an experience report - Codemotion Milan 2017
Andrea Maietta - Il fascino della supercazzola: un breve viaggio nel mondo de...
Gabriele Provinciali/Gabriele Folchi/Luca Postacchini - Sviluppo con piattafo...
Luciano Fiandesio - Docker 101 | Codemotion Milan 2015
From Doctor to Coder: A Whole New World? - Aisha Sie - Codemotion Amsterdam 2017
Alison B Lowndes - Fueling the Artificial Intelligence Revolution with Gaming...
Webinar: Mario Cartia - Facciamo il Punto su Presente e Futuro dei framework ...
Ad

Similar to Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platform - Codemotion Milan 2017 (20)

PDF
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
PDF
Release with confidence
PDF
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
PDF
Original slides from Ryan Dahl's NodeJs intro talk
PDF
soft-shake.ch - Hands on Node.js
PPTX
Async programming and python
PDF
An approach to responsive, realtime with Backbone.js and WebSockets
PDF
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
PPTX
Windows Phone 8 - 3.5 Async Programming
PDF
JavaScript for real men
PDF
Server(less) Swift at SwiftCloudWorkshop 3
PDF
Angular Optimization Web Performance Meetup
ODP
Introduce about Nodejs - duyetdev.com
PDF
"Service Worker: Let Your Web App Feel Like a Native "
PDF
Basic Understanding and Implement of Node.js
PPTX
Introduction to Node.js
PDF
HTML5 tutorial: canvas, offfline & sockets
PDF
Tech friday 22.01.2016
KEY
Writing robust Node.js applications
PDF
Going Serverless with OpenWhisk
HOW TO DEAL WITH BLOCKING CODE WITHIN ASYNCIO EVENT LOOP
Release with confidence
Fundamental Node.js (Workshop bersama Front-end Developer GITS Indonesia, War...
Original slides from Ryan Dahl's NodeJs intro talk
soft-shake.ch - Hands on Node.js
Async programming and python
An approach to responsive, realtime with Backbone.js and WebSockets
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Windows Phone 8 - 3.5 Async Programming
JavaScript for real men
Server(less) Swift at SwiftCloudWorkshop 3
Angular Optimization Web Performance Meetup
Introduce about Nodejs - duyetdev.com
"Service Worker: Let Your Web App Feel Like a Native "
Basic Understanding and Implement of Node.js
Introduction to Node.js
HTML5 tutorial: canvas, offfline & sockets
Tech friday 22.01.2016
Writing robust Node.js applications
Going Serverless with OpenWhisk

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Cloud computing and distributed systems.
PDF
Empathic Computing: Creating Shared Understanding
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The AUB Centre for AI in Media Proposal.docx
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Cloud computing and distributed systems.
Empathic Computing: Creating Shared Understanding
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Lucio Grenzi - Building serverless applications on the Apache OpenWhisk platform - Codemotion Milan 2017