GCP Cloud Functions
Serverless functions on Google Cloud Platform.
Basic Function
# index.js
exports.helloWorld = (req, res) => {
res.send('Hello, World!');
};
# Python
def hello_world(request):
return 'Hello World'
Deploy Function
gcloud functions deploy hello-world \
--runtime nodejs18 \
--trigger-http \
--allow-unauthenticated # make public
List & Delete
gcloud functions list # list all functions
gcloud functions describe hello-world # function details
gcloud functions delete hello-world # delete function
gcloud functions logs read hello-world # view logs
Event Triggers
# Cloud Storage trigger
--trigger-resource my-bucket \
--trigger-event google.storage.object.finalize
# Pub/Sub trigger
--trigger-topic my-topic