Google Cloud Functions
GDG Vienna, 26 April 2017
Google Cloud Functions?
Another serverless Google Cloud option
Based on JavaScript / Node.js
Executed via Triggers
Super-Elastic pricing
Based on JavaScript / Node.js
Add dependencies through package.json
Deploy through a storage "bucket"�gcloud beta functions deploy <NAME> --stage-bucket <BUCKET_NAME> <TRIGGER>
Or through Cloud Source Repositories�gcloud beta functions deploy <NAME> \� --source-url https://source.developers.google.com/p/<PROJECT_ID>/r/<REPOSITORY_ID> \� --source-path <SOURCE> <TRIGGER> [<SOURCE_BRANCH>|<SOURCE_TAG>|<SOURCE_REVISION>]
Triggers
Cloud functions called through external events
Super-Elastic Pricing
Pay as you go
Generous free tier
Sample Code: Hello World
/**� * Cloud Function.� *� * @param {object} event The Cloud Functions event.� * @param {function} The callback function.� */
exports.helloWorld = function helloWorld (event, callback) {� console.log(`My Cloud Function: ${event.data.message}`);� callback();�};
https://cloud.google.com/functions/docs/tutorials/http
Sample Code: Slack Slash Commands
exports.gSearch = function gSearch (req, res) {� return Promise.resolve()� .then(() => {� if (req.method !== 'POST') { /* error … throwing */ }� // Verify that this request came from Slack� verifyWebhook(req.body);� // Make the request to the Knowledge Graph Search API� return makeSearchRequest(req.body.text);� })� .then((response) => {� res.json(response);� })� // ...�};