sergeyradov / workshop

Hands-on labs: Serverless and OpenFaaS with Python

Home Page:https://www.openfaas.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

openfaas-workshop

This is a self-paced workshop for learning how to build, deploy and run OpenFaaS functions.

Translations

This workshop starts by deploying OpenFaaS to your laptop with Docker for Mac or Windows and then shows how to build, deploy and invoke Serverless functions in Python. Topics will include: managing dependencies with pip, dealing with API tokens through secure secrets, monitoring functions with Prometheus, invoking functions asynchronously and chaining functions together to create applications. We finish by creating a GitHub bot which automatically respond to issues. The same method could be applied by connecting to online event-streams through IFTTT.com - this will enable you to build bots, auto-responders and integrations with social media and IoT devices.

Requirements:

We walk through how to install these requirements in Lab 1. Please do Lab 1 before you attend an instructor-led workshop. At the very least you should install Docker and pre-pull the OpenFaaS images.

  • Functions will be written in Python, so prior programming or scripting experience is preferred
  • Install the recommended code-editor / IDE VSCode
  • For Windows install Git Bash
  • Preferred OS: MacOS, Windows 10 Pro/Enterprise, Ubuntu Linux

Docker:

  • Docker CE for Mac/Windows Edge edition
  • Docker CE for Linux

Note: As a last resort if you have an incompatible PC you can run the workshop on https://labs.play-with-docker.com/.

Instructor-led workshops

If you're taking an instructor-led workshops then a link will be shared to join the OpenFaaS Slack community. Use the designated channel for the workshop to discuss comments, questions and suggestions.

Pick your track

  • Swarm track (this page)

The easiest and simplest way to learn about OpenFaaS is through Docker Swarm. The knowledge you build up and the functions you create are both transferrable and portable between Swarm and Kubernetes.

  • Kubernetes track (click link below)

You can also learn about OpenFaaS through Kubernetes. We have a preview available for learning OpenFaaS with Kubernetes. Switch to the Kubernetes track.

  • Install pre-requisites
  • Set up a single-node cluster with Docker Swarm
  • Docker Hub account
  • OpenFaaS CLI
  • Deploy OpenFaaS
  • Use the UI Portal
  • Deploy via the Function Store
  • Learn about the CLI
  • Find metrics with Prometheus
  • Scaffold or generate a new function
  • Build the astronaut-finder function
  • Add dependencies with pip
  • Troubleshooting: find the container's logs
  • Troubleshooting: verbose output with write_debug
  • Use third-party language templates

Build issue-bot - an auto-responder for GitHub Issues

  • Get a GitHub account
  • Set up a tunnel with ngrok
  • Create an webhook receiver issue-bot
  • Receive webhooks from GitHub
  • Deploy SentimentAnalysis function
  • Apply labels via the GitHub API
  • Complete the function
  • Generate and return basic HTML from a function
  • Read and return a static HTML file from disk
  • Collaborate with other functions
  • Call a function synchronously vs asynchronously
  • View the queue-worker's logs
  • Use an X-Callback-Url with requestbin and ngrok
  • Adjust timeouts with read_timeout
  • Accommodate longer running functions
  • See auto-scaling in action
    • Some insights on min and max replicas
    • Discover and visit local Prometheus
    • Execute and Prometheus query
    • Invoke a function using curl
    • Observe auto-scaling kicking in
  • Adapt issue-bot to use a secret
    • Create a Swarm secret
    • Access the secret within the function

You can start with the first lab Lab 1.

  • Apply trust to functions using HMAC

Tear down / Clear up

You can find how to stop and remove OpenFaaS here

Wrapping up

If you're taking an instructor-led workshop, we'll now take Q&A and cover some advanced topics:

  • Auto-scaling
  • Security
    • TLS / Basic Authentication
  • Object storage
  • Customisations for templates

The appendix contains some additional content.

Acknowledgements

Thanks to @iyovcheva, @BurtonR, @johnmccabe, @laurentgrangeau, @stefanprodan, @kenfdev, @templum & @rgee0 for contributing to, testing and translating the labs.

About

Hands-on labs: Serverless and OpenFaaS with Python

https://www.openfaas.com

License:MIT License


Languages

Language:Python 100.0%