Add Google Cloud Python template

Add a template for creating Python Serverless functions in Google Cloud.

Issue(s): None
This commit is contained in:
Serge Dukic 2019-02-09 21:15:04 +13:00
parent d58431566c
commit c1d8e6ec24
4 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,37 @@
# Serverless
.serverless
.env
tmp
.coveralls.yml
# Google
keyfile.json
# Logs
*.log
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
# IDE
**/.idea
# OS
.DS_Store
.tmp

View File

@ -0,0 +1,11 @@
def pyhttp(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values that can be turned into a
Response object using
`make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
"""
return f'Hello World!'

View File

@ -0,0 +1,14 @@
{
"name": "google-python",
"version": "0.1.0",
"description": "",
"main": "main.py",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "serverless.com",
"license": "MIT",
"devDependencies": {
"serverless-google-cloudfunctions": "*"
}
}

View File

@ -0,0 +1,48 @@
service: gcf-python# NOTE: Don't put the word "google" in here
provider:
name: google
stage: dev
runtime: python37
region: us-central1
project: my-project
# The GCF credentials can be a little tricky to set up. Luckily we've documented this for you here:
# https://serverless.com/framework/docs/providers/google/guide/credentials/
#
# the path to the credentials file needs to be absolute
credentials: ~/.gcloud/keyfile.json
plugins:
- serverless-google-cloudfunctions
# needs more granular excluding in production as only the serverless provider npm
# package should be excluded (and not the whole node_modules directory)
package:
exclude:
- node_modules/**
- .gitignore
- .git/**
functions:
first:
handler: http
events:
- http: path
# NOTE: the following uses an "event" event (pubSub event in this case).
# Please create the corresponding resources in the Google Cloud
# before deploying this service through Serverless
#second:
# handler: event
# events:
# - event:
# eventType: providers/cloud.pubsub/eventTypes/topic.publish
# resource: projects/*/topics/my-topic
# you can define resources, templates etc. the same way you would in a
# Google Cloud deployment configuration
#resources:
# resources:
# - type: storage.v1.bucket
# name: my-serverless-service-bucket
# imports:
# - path: my_template.jinja