Google Cloud Functions

From XennisWiki
Jump to: navigation, search

Service of the Google Cloud Platform of a serverless compute platform.

Setup

Enable the API

gcloud services enable cloudfunctions.googleapis.com

Usage

Deploy a function

Deploy a function with a Python environment and Google Cloud Pub/Sub as trigger

gcloud functions deploy <name> \
    --runtime python37 \
    --trigger-topic <topic> \
    --region europe-west1

Use --service-account <name>@<gcp-project>.iam.gserviceaccount.com to set a custom service account (Note: beta gcloud components are required for that.)

Set environment variables from a file

Create a file .env.yaml

TOPIC: my-topic
NAME: example

Use it in the deploy command

gcloud functions deploy <name> --env-vars-file .env.yaml OTHER-ARGUMENTS...

Use the argument --clear-env-vars to remove all set variables.

See also

External links