Serverless Functions Made Simple
OpenFaaS
DOCKER CAMBRIDGE
@alexellisuk
What is Serverless?
MicroserviceMicroserviceMicroservice
Monolith
Microservice
Function
Serverless	evolu*on
OpenFaaS
DRIVING FACTORS
“Alexa, how’s
the weather?”
{ “intent”:
“FindWeather” }
{ “speech”:
“It’s 70 degrees” }
Lambda
Function
“Alexa, how’s
the weather?”
{ “intent”:
“FindWeather” }
{ “speech”:
“It’s 70 degrees” }
+
What are serverless use-cases?
ANYTHING - WINDOWS/LINUX
Image/Video
conversion
Machine
Learning
Mobile Back-
ends / IoT
HTTP API /
Integrations
Chat Bots
Batch Jobs
How did OpenFaaS come about?
STORY SO FAR
• “Lambda but with containers for Alexa”
• Dockercon Cool Hacks - “push Docker beyond what it was designed to do”
• Since May
• Top trending Open Source project overall
• > 8k stars
• Industry Award
• Production users
• Kubernetes, Nomad, Hyper.sh, Cattle
Commits: 876, Forks: 372 Stars: 6589
OpenFaaS top contributors and influencers
You..
1.3k commits, 60+ contributors, 533 forks
Comes in one flavor: Cloud Native
API Gateway Function Watchdog
Prometheus Swarm Kubernetes
HTTP
body
stdinrequest
stdoutresponse
“python3

main.py”
headers
body
headers
Forked process
Function watchdog
Performance - fork vs After Burn
HELLO-WORLD & APACHE-BENCH
OpenFaaS values
Portable
Developer-
First
Unsurprising UNIX-like
Operator-
Friendly
Community-
Centric
Framework
Developer
Love
Mobilized
Cloud Native
Building a Twitter bot
Building a Twitter bot
@COLORISEBOT
Gateway Colorise
Tweet-pic
Normalise-color
Minio
Tweet-listener
Deployed in 60 seconds
How do I write a function?
WRITE A HANDLER
def handler(req):
r = requests.get(req)
print(r.status_code)
handler.py
requirements.txt
Python
Template
Docker
Image
requests
$ faas-cli new dockercon --lang python
Container Registry
How do I arrange functions?
provider:
name: faas
url-ping:
lang: python
handler: ./sample/url-ping
image: of/url-ping
environment:
http_proxy: http://corp1.com
notify-slack:
lang: python
handler: ./sample/notify-slack
image: of/notify-slack
$ faas-cli build -f ./sample.yml
$ faas-cli deploy -f ./sample.yml
YAML STACK
$ faas-cli new url-ping --lang python
Synchronous invocation
IN STORE RETURNS
marshal	request
Gateway Func: resizer
HTTP

200
Resize

Image
Asynchronous invocation
RETURN A PRODUCT BY MAIL
NATS Queue
marshal	request
Gateway Queue-worker
dequeue
Func: resizer
HTTP

200
HTTP

200
Resize

Image
Asynchronous invocation
WITH A CALLBACK-URL
Gateway Func: resizer
HTTP

200
http://x.y.z
X-Callback-Url:	
hFp://x.y.z
X-Callback-Url
Resize

Image
Queue etc
github.com/openfaas/faas
Chaining demo
FanClub GetAvatar
hFps://
Twitter
Chaining demo - Fanclub
HOW IT WORKS
Polaroid
Chaining / workflows
AS FUNCTIONS
• Should be a function
• A can call B directly
• A can call B via gateway
• Async
• Director pattern (in documentation)
• Helper library available
Providers, integrations and users
DON’T TAKE MY WORD FOR IT
Follow @openfaas for more
https://www.openfaas.com

Docker Cambridge: Serverless Functions Made Simple with OpenFaaS