Cloud function
Introduction
Google Cloud Functions is a serverless execution environment for building and connecting cloud services.
With Cloud Functions you write simple, single-purpose functions that are attached to events emitted from your cloud infrastructure and services. Your function is triggered when an event being watched is fired. Your code executes in a fully managed environment.
Cloud Functions are written in Javascript and execute in a managed Node.js environment on Google Cloud Platform. Events from Cloud Storage and Cloud Pub/Sub can trigger Cloud Functions asynchronously, or you can use HTTP invocation for synchronous execution.
Cloud function can be triggered by pub/sub , bucket changes , firestore document changes and http call
Operation
Created function and deploy
* Background Cloud Function to be triggered by Pub/Sub.
* This function is exported by index.js, and executed when
* the trigger topic receives a message.
*
* @param {object} data The event payload.
* @param {object} context The event metadata.
*/
exports.helloWorld = (data, context) => {
const pubSubMessage = data;
const name = pubSubMessage.data
? Buffer.from(pubSubMessage.data, 'base64').toString() : "Hello World";
console.log(`My Cloud Function: ${name}`);
};
gcloud functions deploy helloWorld \
--trigger-topic hello_world \
--runtime nodejs8
gcloud functions describe helloWorld
Last updated
Was this helpful?