This is a half-hour technical talk on serverless computing with Python featuring products from the Google Cloud Platform. It starts with a review of all of cloud computing then dives into serverless computing, demonstrates multiple products, then shows inspirational examples of apps built using these technologies.
Advantages of Hiring UIUX Design Service Providers for Your Business
Serverless Computing with Python
1. Serverless Computing with Python
Wesley Chun
Developer Advocate, Google
G Suite Dev Show
goo.gl/JpBQ40
About the speaker
Developer Advocate, Google Cloud
● Mission: enable current and future
developers everywhere to be
successful using Google Cloud and
other Google developer tools & APIs
● Videos: host of the G Suite Dev Show
on YouTube
● Blogs: developers.googleblog.com &
gsuite-developers.googleblog.com
● Twitters: @wescpy, @GoogleDevs,
@GSuiteDevs
Previous experience / background
● Software engineer & architect for 20+ years
● One of the original Yahoo!Mail engineers
● Author of bestselling "Core Python" books
(corepython.com)
● Technical trainer, teacher, instructor since
1983 (Computer Science, C, Linux, Python)
● Fellow of the Python Software Foundation
● AB (Math/CS) & CMP (Music/Piano), UC
Berkeley and MSCS, UC Santa Barbara
● Adjunct Computer Science Faculty, Foothill
College (Silicon Valley)
3. What is cloud computing?
spar
Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Cloud service levels/"pillars"
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce1/force.com
G Suite (Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
4. Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Outsourcing of apps (SaaS)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce1/force.com
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
G Suite (Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Outsourcing of hardware (IaaS)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce1/force.com
G Suite (Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
5. Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
Outsourcing of logic-hosting (PaaS)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Apps Script
Salesforce1/force.com
G Suite (Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
IaaS/PaaS gray area (DataB/S/P-aaS?)
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google Apps Script
Salesforce1/force.com
G Suite (Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
6. Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
SaaS/PaaS gray area
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
G Suite (Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google Apps Script
Salesforce1/force.com
Summary of responsibility
SaaS
Software as a Service
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
IaaS
Infrastructure as a Service
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
PaaS
Platform as a Service
Managed by YOU Managed by cloud vendor
Applications
Data
Runtime
Middleware
OS
Virtualization
Servers
Storage
Networking
on-prem
all you, no cloud
8. Compute
Big Data
BigQuery
Cloud
Dataflow
Cloud
Dataproc
Cloud
Datalab
Cloud
Pub/Sub
Genomics
Cloud AI/ML
Cloud Machine
Learning Engine
Cloud
Vision
Cloud
Speech-to-Text
Cloud Natural
Language
Cloud
Translation
Cloud
Jobs
Cloud
Dataprep
Cloud Video
Intelligence
Advanced
Solutions Lab
Compute
Engine
App
Engine
Kubernetes
Engine
GPU
Cloud
Functions
Identity & Security
Cloud IAM
Cloud Resource
Manager
Cloud Security
Scanner
Key
Management
Service
BeyondCorp
Data Loss
Prevention
Identity-Aware
Proxy
Security Key
Enforcement
Cloud
AutoML
Cloud
Text-to-Speech
Cloud TPU
DialogFlow
Enterprise
Edition
Cloud
Composer
Cloud Security
Command
Center
Cloud Run
AutoML
Tables
Developer Tools
Cloud SDK
Cloud Source
Repositories
Maven App
Engine Plugin
Cloud Tools
for IntelliJ
Cloud
Tools for
PowerShell
Cloud
Tools for
Visual Studio
Container
Registry
Cloud Tools
for Eclipse
Cloud Build
API Platform & Ecosystems
API
Analytics
API
Monetization
Apigee API
Platform
Apigee
Sense
Cloud
Endpoints
Developer
Portal
Gradle App
Engine Plugin
IDE plugins
Internet of Things
Cloud IoT
Core
Data (storage,
databases, transfer)
Cloud
Storage
Cloud
Bigtable
Cloud
Datastore
Cloud SQL
Cloud
Spanner
Persistent
Disk
Cloud
Memorystore
Cloud
Filestore
Cloud
Test Lab
Cloud IoT
Edge
Container-
Optimized OS
Healthcare
API
Cloud Code
Cloud
Firestore
Transfer
Appliance
9. Networking
Virtual
Private Cloud
Cloud Load
Balancing
Cloud
CDN
Dedicated
Interconnect
Cloud DNS
Cloud
Network
Cloud
External IP
Addresses
Cloud
Firewall Rules
Cloud
Routes
Cloud VPN
Management Tools
Stackdriver Monitoring Logging
Error
Reporting
Trace
Debugger
Cloud
Deployment
Manager
Cloud
Console
Cloud
Shell
Cloud Mobile
App
Cloud
Billing API
Cloud
APIs
Cloud
Router
Partner
Interconnect
Cloud Armor
Standard
Network Tier
Premium
Network Tier
Profiler
GCP products and
services without a
unique icon have a
generic hexagon.
Cloud NAT
G Suite APIs
Top-level documentation and comprehensive developers
overview video at developers.google.com/gsuite
10. Google Compute Engine, Google Cloud Storage
AWS EC2 & S3; Rackspace; Joyent
SaaS
Software as a Service
PaaS
Platform as a Service
IaaS
Infrastructure as a Service
Google Apps Script
Salesforce1/force.com
G Suite (Google Apps)
Yahoo!Mail, Hotmail, Salesforce, Netsuite, Office 365
Google App Engine, Cloud Functions
Heroku, Cloud Foundry, Engine Yard, AWS Lambda
Google BigQuery, Cloud SQL,
Cloud Datastore, NL, Vision, Pub/Sub
AWS Kinesis, RDS; Windows Azure SQL, Docker
Google Cloud Platform vs. G Suite
G Suite
APIs
GCP
APIs
3
Run your code on
Google Cloud serverless
GCP: Google App Engine , Google Cloud Functions
G Suite: Google Apps Script , Google App Maker
11. > Google Compute Engine configurable
VMs of all shapes & sizes, from
"micro" to 416 vCPUs, 11.776 TB
RAM, 256 TB HDD/SSD plus Google
Cloud Storage for data lake "blobs"
(Debian, CentOS, CoreOS, SUSE, Red Hat Enterprise Linux,
Ubuntu, FreeBSD; Windows Server 2008 R2, 2012 R2, 2016, 1803,
1809, 1903/2019, 1909)
cloud.google.com/compute
cloud.google.com/storage
Yeah, we got VMs & big disk… but why*?
Serverless: what & why
● What is serverless?
○ Misnomer
○ "No worries"
○ Developers focus on writing code & solving business problems*
● Why serverless?
○ Fastest growing segment of cloud... per analyst research*:
■ $1.9B (2016) and $4.25B (2018) ⇒ $7.7B (2021) and $14.93B (2023)
○ What if you go viral? Autoscaling: your new best friend
○ What if you don't? Code not running? You're not paying.
* in USD; source:Forbes (May 2018), MarketsandMarkets™ & CB Insights (Aug 2018)
12. Google App Engine
App-hosting in the cloud
Why does App Engine exist?
● Focus on app not DevOps
○ Web app
○ Mobile backend
○ Cloud service
● Enhance productivity
● Deploy globally
● Fully-managed
● Auto-scaling
● Pay-per-use
● Familiar languages
13. Not all apps user-facing or web-based!!
● Need backend processing? Want to build your own?
● No UI required... just need HTTP
● Optimal for user info (high scores, contacts, levels/badges, etc.)
● Better UI: move user data off phone so it's universally available
Popular App Engine Use Cases
● Mobile/Tablet
○ App backends
○ Cloud persistence
● Social/Mobile Games
○ Speed, scale
○ API integrations
○ Personals/dating
● Consumer Web Apps
○ Unpredictable traffic
○ Scale (up or down)
● Apps in Academia
○ Any course where students
build web or mobile apps
○ Research projects
○ IT/Operational apps
● Business Apps
○ Enterprise
○ Java runtime
○ IT/Operational apps
○ Web or Mobile
15. Google Cloud Functions
Function-hosting in the cloud
Why does Cloud Functions exist?
● Don't have entire app?
○ No framework "overhead" (LAMP, MEAN...)
○ Deploy microservices
● Event-driven
○ Triggered via HTTP or background events
■ Pub/Sub, Cloud Storage, Firebase, etc.
○ Auto-scaling & highly-available; pay per use
● Flexible development environment
○ Cmd-line or developer console (in-browser)
● Cloud Functions for Firebase
○ Mobile app use-cases
● Available runtimes
○ JS/Node.js 6, 8, 10
○ Python 3.7
○ Go 1.11, 1.12
○ Java 8
16. To create a function
Create function code locally then deploy on cmd-line
OR
1. Go to developer console @ console.cloud.google.com
2. Select a project (or create new one)
3. Choose Cloud Functions, then "Create Function"
4. Select name, memory, trigger type, language, etc.
5. Write code in browser then click to deploy (and test)
17. Events and triggers
Events trigger cloud functions to execute. A trigger is the type of event
that's recognized for any specific function. Functions can only be bound to
1 trigger type at a time.
EVENTS (i.e., functions are invoked when…)
1. HTTP — via HTTP request
2. Cloud Storage — bucket object/metadata CRUD
3. Cloud Pub/Sub — new message
4. Firebase (DB, Storage, Analytics, Auth)
5. Direct — CLI or developer console requests
6. others
main.py
def hello_world(request):
return 'Hello World!'
Deploy:
$ gcloud functions deploy hello --runtime python37 --trigger-http
Access globally (curl):
curl -X POST https://GCP_REGION-PROJECT_ID.cloudfunctions.net/hello
-H "Content-Type:application/json"
Access globally (browser):
GCP_REGION-PROJECT_ID.cloudfunctions.net/hello
Hello World (Python "MVP")
Quickstart tutorial and open source repo at
cloud.google.com/functions/docs/quickstart-python
18. No cmd-line
access?
Use in-browser
dev environment!
● setup
● code
● deploy
● test
Cloud Functions
"get started"
Python QuickStart tutorial
(also in Node.js & Go)
19. Google Cloud Run
Container-hosting in the cloud
The rise of containers... ● Any language
● Any library
● Any binary
● Ecosystem of base images
● Industry standard
FLEXIBILITY
20. Cloud Run: code, build, deploy
.js .rb .go
.sh.py ...
● Any language, library, binary
○ HTTP port, stateless
● Bundle into container
○ Build w/Docker OR
○ Google Cloud Build
○ Image ⇒ Container Registry
● Deploy to Cloud Run (managed or GKE)
StateHTTP
CONT_NAME-RANDOM_HASH-
uREGION.a.run.app
“We can’t be locked in.”
“How can we use
existing binaries?”
“Why do I have to choose between
containers and serverless?”
“Can you support language _______ ?”
Serverless inaccessible for some...
CONVENIENCE
21. ● Fully-managed serverless execution environment
○ Run stateless HTTP-driven containers
○ Without worrying about infrastructure
● Autoconfiguring, autoprovisioning, autoscaling
○ Including scaling down to zero
○ Only pay for what you use
● Anti-vendor lock-in: portable to GKE or, with
Knative, to your self-managed Kubernetes cluster
Introducing Google Cloud Run
● Fully-managed serverless "CaaS"
○ Flexibility and portability of containers, but
with the convenience of serverless
○ You app, your bundled container
○ Auto-scale, -provision, -config
○ Pay-per-use
● Anti-vendor lock-in, portable to:
○ Google-managed Kubernetes cluster (GKE)
○ Or your self-managed Kubernetes cluster
Google Cloud Run to the rescue!
22. Hello World (Python "MVP")
app.py
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
target = os.environ.get('TARGET', 'World')
return 'Hello {}!'.format(target)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
cloud.google.com/run/docs/quickstarts/build-and-deploy or
github.com/knative/docs/tree/master/docs/serving/samples/h
ello-world/helloworld-python
Hello World (Python "MVP")
Dockerfile
FROM python:3-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
.dockerignore
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
Build (think docker build and docker push):
$ gcloud builds submit --tag gcr.io/PROJ_ID/CONT_NAME
Deploy (think docker run):
$ gcloud run deploy --image gcr.io/PROJ_ID/CONT_NAME --platform managed
Access globally:
CONT_NAME-RANDOM_HASH-uREGION.a.run.app
23. Cloud Run
"get started"
Python QuickStart tutorial
(also in Node.js, Go, Java, C#/.NET, Ruby, etc.)
Google Apps Script
Customized serverless JS runtime for automation, and extension
and integration with G Suite, Google, or other external services
25. 4 All of Cloud (inspiration)
Build with both GCP tools and G Suite
Hangouts Chat Productivity Tracker
Chat bot that's GCP & G Suite aware
26. Productivity tracker Hangouts Chat bot
G Suite GCP
Sheets Natural Language
START
or LOG
END
Hangouts
Chat
App
Engine
Cloud
SQL
27. App summary
● Motivation
● Do coding contract jobs during school year
● Needed to track time spent on work (and non-work)
● Who doesn't want to be more productive?
● Hangouts Chat bot framework & API... build bots to:
● Automate workflows
● Query for information
● Other heavy-lifting
● G Suite app that leverages app-hosting, NL processing, and storage tools from GCP
● Application source code
● github.com/gsuitedevs/hangouts-chat-samples/tree/master/python/productivity_tracker
● Presented at GDG Silicon Valley (Aug 2018)
● meetup.com/gdg-silicon-valley/events/252858660
Using Google Docs as an IDE
Running Python code in Docs w/the help of GCP
28. Google Docs as a Code Editor/IDE
GCP G Suite
Docs
New Roster,
New Editors
Run Code
Edit Roster
Edit Code
Cloud
Functions
Compute
Engine
Drive
Sheets
New Roster,
New Editors
29. App summary
● Motivation
● Lead TA during school year; manage student coursework
● Needed roster app for non-engineering faculty for student coding
● Use two new products (Docs API and Python Cloud Functions)
● Implementation
● Use Drive & Sheets APIs to create student roster Sheet for professor
● Faculty completes roster in Sheet, calls Cloud Function again
● Autogenerate "Docs IDE" per student via Docs API
● Student edits code in Doc, then calls Cloud Function to run
● Read from Doc, spin-up GCE VM, run code, write results into Doc, bring down VM
● Application source code (to-be-published)
● github.com/gsuitedevs/python-samples/tree/master/docs/docs_editor
Online resources & summary
What's available for students & educators?5
30. Cloud computing session summary
● Why go cloud?
○ Cloud computing has taken the world by storm
○ You're behind if you're not already using it… it's not too late!
○ Help train the next generation cloud-ready workforce!
● Google Cloud and why serverless?
○ Many features: compute, storage, AI/ML, NW, data processing, etc.
○ Serverless lets users focus on just their logic (apps or functions)
○ Interesting possibilities using both platforms (GCP + G Suite)
Other Google APIs & platforms
● Firebase (mobile development platform + RT DB; ML Kit)
○ firebase.google.com & firebase.google.com/docs/ml-kit
● Google Data Studio (data visualization, dashboards, etc.)
○ datastudio.google.com/overview
○ goo.gle/datastudio-course
● Actions on Google/Assistant/DialogFlow (voice apps)
○ developers.google.com/actions
● YouTube (Data, Analytics, and Livestreaming APIs)
○ developers.google.com/youtube
● Google Maps (Maps, Routes, and Places APIs)
○ developers.google.com/maps
● Flutter (native apps [Android, iOS, web] w/1 code base[!])
○ flutter.dev
31. ● Documentation
○ GCP: cloud.google.com/{docs,appengine,functions,run,vision,automl,translate,language,
speech,texttospeech,video-intelligence,firestore,bigquery,compute,storage,gpu,tpu}
○ G Suite: developers.google.com/{gsuite,drive,calendar,gmail,docs,sheets,slides,apps-script}
● Introductory "codelabs" ([free] self-paced, hands-on tutorials)
○ App Engine: codelabs.developers.google.com/codelabs/cloud-app-engine-python
○ Cloud Functions: codelabs.developers.google.com/codelabs/cloud-starting-cloudfunctions
○ Cloud Run: codelabs.developers.google.com/codelabs/cloud-run-hello-python3
● Other codelabs: gcplab.me (GCP) and codelabs.developers.google.com/?cat=G+Suite (G Suite)
● Videos: youtube.com/GoogleCloudPlatform (GCP) and goo.gl/JpBQ40 (G Suite)
● Code samples: github.com/GoogleCloudPlatform (GCP) and github.com/gsuitedevs (G Suite)
● Python on Google Cloud - cloud.google.com/python
● Know AWS/Azure? Compare w/GCP at cloud.google.com/docs/compare/{aws,azure}
Resources (industry)
Thank you! Questions?
Wesley Chun
@wescpy