Google Cloud Cheatsheet

Cloud Functions

Use this Google Cloud reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Supported Runtimes

RuntimeFlag
Node.js 22nodejs22
Node.js 20 (LTS)nodejs20
Python 3.13python313
Python 3.12python312
Go 1.23go123
Java 21java21
Ruby 3.3ruby33
PHP 8.3php83
.NET 8dotnet8

Node.js 18 is decommissioned — redeploy old functions on nodejs20/nodejs22.

Function Management

# List functions
gcloud functions list --region=us-central1

# Describe (shows trigger URL, runtime, etc.)
gcloud functions describe my-function --gen2 --region=us-central1

# Get just the trigger URL
gcloud functions describe my-function \
  --gen2 --region=us-central1 \
  --format="value(serviceConfig.uri)"

# Delete a function
gcloud functions delete my-function --gen2 --region=us-central1

Resource Configuration

# Memory, CPU, timeout, concurrency
gcloud functions deploy my-function \
  --gen2 \
  --runtime=nodejs20 \
  --region=us-central1 \
  --source=. \
  --entry-point=myHandler \
  --trigger-http \
  --memory=512Mi \
  --cpu=1 \
  --timeout=120s \
  --concurrency=10 \
  --min-instances=0 \
  --max-instances=50 \
  --allow-unauthenticated
SettingDefaultRange
Memory256 Mi128 Mi – 32 Gi
CPU0.3330.083 – 8
Timeout60 s1 s – 3600 s
Concurrency1 (gen1) / 80 (gen2)1 – 1000
Max instances100Up to 3000

Environment Variables & Secrets

# Set env vars at deploy time
gcloud functions deploy my-function \
  --gen2 --runtime=nodejs20 --region=us-central1 \
  --source=. --entry-point=myHandler --trigger-http \
  --set-env-vars="DB_HOST=10.0.0.1,ENV=production"

# Update env vars only (no redeploy of code)
gcloud functions deploy my-function \
  --gen2 --region=us-central1 \
  --update-env-vars="LOG_LEVEL=debug"

# Mount Secret Manager secret
gcloud functions deploy my-function \
  --gen2 --runtime=nodejs20 --region=us-central1 \
  --source=. --entry-point=myHandler --trigger-http \
  --set-secrets="API_KEY=my-api-key:latest"

HTTP Function Example (Node.js)

// index.js
const functions = require('@google-cloud/functions-framework');

functions.http('myHandler', (req, res) => {
  const name = req.query.name || req.body.name || 'World';
  res.send(`Hello, ${name}!`);
});

Pub/Sub Function Example (Python)

# main.py
import base64
import functions_framework

@functions_framework.cloud_event
def handle_message(cloud_event):
    data = base64.b64decode(cloud_event.data["message"]["data"]).decode()
    print(f"Received: {data}")

Triggering

# Invoke an HTTP function manually
curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" \
  https://us-central1-my-project.cloudfunctions.net/my-function

# Publish to Pub/Sub to trigger a Pub/Sub function
gcloud pubsub topics publish my-pubsub-topic --message="hello"

# Schedule via Cloud Scheduler (HTTP)
gcloud scheduler jobs create http daily-trigger \
  --location=us-central1 \
  --schedule="0 9 * * *" \
  --uri="https://us-central1-my-project.cloudfunctions.net/my-function" \
  --oidc-service-account-email=scheduler-sa@proj.iam.gserviceaccount.com

Authentication

# Require authentication (remove allUsers binding)
gcloud functions remove-iam-policy-binding my-function \
  --gen2 --region=us-central1 \
  --member=allUsers --role=roles/cloudfunctions.invoker

# Grant invocation to a specific account
gcloud functions add-iam-policy-binding my-function \
  --gen2 --region=us-central1 \
  --member=user:alice@example.com \
  --role=roles/cloudfunctions.invoker

Logs

# View recent logs
gcloud functions logs read my-function --gen2 --region=us-central1 --limit=50

# Stream logs
gcloud beta functions logs tail my-function --gen2 --region=us-central1

Gen 1 vs Gen 2

FeatureGen 1Gen 2
Underlying runtimeCloud FunctionsCloud Run
Max timeout540 s3600 s
Max memory8 GiB32 GiB
Concurrency1 per instanceUp to 1000
Traffic splittingNoYes
Min instancesYesYes
VPC accessLimitedFull

Use Gen 2 for all new functions. Gen 1 is in maintenance mode.