際際滷

際際滷Share a Scribd company logo
Go Serverless with
Cloud Functions and
Python
Faz
Solutions Architect, Randstad
Go Serverless with Cloud Functions and Python
No Servers? Really??
Cloud Functions
A serverless environment to build and connect
cloud services with code
Cloud Functions
import flask
import requests
def getUserDetails(request):
user = requests.get('https://randomuser.me/api/').json()
user = user['results'][0]
user['generator'] = 'google-cloud-function'
return flask.jsonify(user)
main.py
Upload
{
"cell": "(49) 7509-0459",
"dob": {
"age": 23,
"date": "1994-11-20T14:16:08Z"
},
"email": "otoniel.darosa@example.com",
"gender": "male",
"generator": "google-cloud-function",
"id": {
"name": "",
"value": null
},
"location": {
"city": "su00e3o bernardo do campo",
"coordinates": {
"latitude": "-79.1409",
"longitude": "-56.7472"
},
"postcode": 64898,
"state": "maranhu00e3o",
"street": "7364 rua treze ",
"timezone": {
"description": "Kabul",
"offset": "+4:30"
"login": {
"md5": "715e1b0e40d34aa4f1b71a8cd1a3a485",
"password": "devil666",
"salt": "uWgXRkVk",
"sha1": "ac5b60ddf5a17d1f949ac4a9821099c7178447f1",
"sha256":
"881dd91e9ad2c9f698ab604b4ca0925d645446a83e6b9a90458c1411943eae
b0",
"username": "ticklishleopard379",
"uuid": "c5abdd59-5c1c-4b2c-a4d8-4fd08da1cf18"
},
"name": {
"first": "otoniel",
"last": "da rosa",
"title": "mr"
},
"nat": "BR",
"phone": "(58) 6179-0550",
"picture": {
"large": "https://randomuser.me/api/portraits/men/5.jpg",
"medium": "https://randomuser.me/api/portraits/med/men/5.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/men/5.jpg"
},
"registered": {
"age": 3,
"date": "2015-06-04T04:09:38Z"
}
}
Output
With 3 lines of code..
¢ HTTP endpoint
¢ Fully qualified domain
¢ Dynamically generated SSL/TLS cert
¢ Autoscaling
¢ No infrastructure worries
Use cases
Should I go serverless with Cloud Functions?
¢ Existing monolithic applications
¢ Long-running compute tasks
¢ Guaranteed response times (synchronous)
¢ Stateless / ephemeral
Thanks!
https://www.facebook.com/gcdckualalumpur/

More Related Content

Go Serverless with Cloud Functions and Python

  • 1. Go Serverless with Cloud Functions and Python Faz Solutions Architect, Randstad
  • 4. Cloud Functions A serverless environment to build and connect cloud services with code
  • 6. import flask import requests def getUserDetails(request): user = requests.get('https://randomuser.me/api/').json() user = user['results'][0] user['generator'] = 'google-cloud-function' return flask.jsonify(user) main.py
  • 8. { "cell": "(49) 7509-0459", "dob": { "age": 23, "date": "1994-11-20T14:16:08Z" }, "email": "otoniel.darosa@example.com", "gender": "male", "generator": "google-cloud-function", "id": { "name": "", "value": null }, "location": { "city": "su00e3o bernardo do campo", "coordinates": { "latitude": "-79.1409", "longitude": "-56.7472" }, "postcode": 64898, "state": "maranhu00e3o", "street": "7364 rua treze ", "timezone": { "description": "Kabul", "offset": "+4:30" "login": { "md5": "715e1b0e40d34aa4f1b71a8cd1a3a485", "password": "devil666", "salt": "uWgXRkVk", "sha1": "ac5b60ddf5a17d1f949ac4a9821099c7178447f1", "sha256": "881dd91e9ad2c9f698ab604b4ca0925d645446a83e6b9a90458c1411943eae b0", "username": "ticklishleopard379", "uuid": "c5abdd59-5c1c-4b2c-a4d8-4fd08da1cf18" }, "name": { "first": "otoniel", "last": "da rosa", "title": "mr" }, "nat": "BR", "phone": "(58) 6179-0550", "picture": { "large": "https://randomuser.me/api/portraits/men/5.jpg", "medium": "https://randomuser.me/api/portraits/med/men/5.jpg", "thumbnail": "https://randomuser.me/api/portraits/thumb/men/5.jpg" }, "registered": { "age": 3, "date": "2015-06-04T04:09:38Z" } } Output
  • 9. With 3 lines of code.. ¢ HTTP endpoint ¢ Fully qualified domain ¢ Dynamically generated SSL/TLS cert ¢ Autoscaling ¢ No infrastructure worries
  • 11. Should I go serverless with Cloud Functions? ¢ Existing monolithic applications ¢ Long-running compute tasks ¢ Guaranteed response times (synchronous) ¢ Stateless / ephemeral