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.
Deploy a Function (Gen 2 — recommended)
Cloud Functions was renamed Cloud Run functions in 2024 — gen 2 functions are Cloud Run services under the hood. The
gcloud functionsCLI and the concepts below are unchanged.
# HTTP-triggered function from source directory gcloud functions deploy my-function \ --gen2 \ --runtime=nodejs20 \ --region=us-central1 \ --source=. \ --entry-point=myHandler \ --trigger-http \ --allow-unauthenticated # Pub/Sub-triggered function gcloud functions deploy process-messages \ --gen2 \ --runtime=python312 \ --region=us-central1 \ --source=. \ --entry-point=handle_message \ --trigger-topic=my-pubsub-topic # Cloud Storage-triggered function gcloud functions deploy process-uploads \ --gen2 \ --runtime=go123 \ --region=us-central1 \ --source=. \ --entry-point=HandleUpload \ --trigger-bucket=my-bucket
Supported Runtimes
| Runtime | Flag |
|---|---|
| Node.js 22 | nodejs22 |
| Node.js 20 (LTS) | nodejs20 |
| Python 3.13 | python313 |
| Python 3.12 | python312 |
| Go 1.23 | go123 |
| Java 21 | java21 |
| Ruby 3.3 | ruby33 |
| PHP 8.3 | php83 |
| .NET 8 | dotnet8 |
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
| Setting | Default | Range |
|---|---|---|
| Memory | 256 Mi | 128 Mi – 32 Gi |
| CPU | 0.333 | 0.083 – 8 |
| Timeout | 60 s | 1 s – 3600 s |
| Concurrency | 1 (gen1) / 80 (gen2) | 1 – 1000 |
| Max instances | 100 | Up 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
| Feature | Gen 1 | Gen 2 |
|---|---|---|
| Underlying runtime | Cloud Functions | Cloud Run |
| Max timeout | 540 s | 3600 s |
| Max memory | 8 GiB | 32 GiB |
| Concurrency | 1 per instance | Up to 1000 |
| Traffic splitting | No | Yes |
| Min instances | Yes | Yes |
| VPC access | Limited | Full |
Use Gen 2 for all new functions. Gen 1 is in maintenance mode.