Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Cloud (AWS/GCP/Azure)intermediate

Cloud Functions GCP

Share

Create Google Cloud Functions

Works with OpenClaude

You are a Google Cloud Platform developer. The user wants to create and deploy a Google Cloud Function using the gcloud CLI and Cloud Functions API.

What to check first

  • Run gcloud auth list to verify you're authenticated to GCP
  • Run gcloud config list to confirm your project ID is set correctly
  • Ensure you have the Cloud Functions API enabled: gcloud services enable cloudfunctions.googleapis.com
  • Check your local gcloud version with gcloud --version (requires v300+)

Steps

  1. Create a new directory for your function and initialize it: mkdir my-function && cd my-function
  2. Create your function code file (main.py for Python or index.js for Node.js)
  3. Create a requirements.txt (Python) or package.json (Node.js) listing dependencies
  4. Choose your trigger type: HTTP, Pub/Sub, Cloud Storage, Firestore, or Cloud Tasks
  5. Deploy using gcloud functions deploy [FUNCTION_NAME] with appropriate flags for runtime, trigger-type, and entry-point
  6. Verify deployment completed: gcloud functions describe [FUNCTION_NAME]
  7. Test the function using gcloud functions call [FUNCTION_NAME] or curl the HTTP endpoint
  8. Monitor logs with gcloud functions logs read [FUNCTION_NAME] --limit 50

Code

# main.py - HTTP Cloud Function example
import functions_framework
import json
from datetime import datetime

@functions_framework.http
def hello_world(request):
    """HTTP Cloud Function to process requests."""
    
    try:
        # Parse request JSON
        request_json = request.get_json(silent=True)
        request_args = request.args
        
        # Extract parameters with defaults
        name = request_json.get('name') if request_json else None
        name = request_args.get('name') if not name else name
        name = name or 'World'
        
        # Build response
        response = {
            'message': f'Hello, {name}!',
            'timestamp': datetime.utcnow().isoformat(),
            'function': 'hello_world'
        }
        
        return json.dumps(response), 200, {'Content-Type': 'application/json'}
    
    except Exception as e:
        error_response = {
            'error': str(e),
            'timestamp': datetime.utcnow().isoformat()
        }
        return json.dumps(error_response), 500, {'Content-Type': 'application/json'}

# Deploy with:
# gcloud functions deploy hello_world \
#   --runtime python39 \
#   --trigger-http \
#   --allow-unauthenticated \
#   --entry-point hello_world \
#   --region us-central1

# Test with:
# curl "https://REGION-PROJECT_ID.cloudfunctions.net

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
cloudgcpfunctions

Install command:

curl -o ~/.claude/skills/cloud-functions-gcp.md https://claude-skills-hub.vercel.app/skills/cloud/cloud-functions-gcp.md

Related Cloud (AWS/GCP/Azure) Skills

Other Claude Code skills in the same category — free to download.

Want a Cloud (AWS/GCP/Azure) skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.