jpskill.com
🛠️ 開発・MCP コミュニティ

gcp-cloud-functions

Google Cloud Functions上でサーバーレス関数を構築し、Pub/SubやCloud Storageなどのイベントをトリガーに関数を実行、ランタイム設定や依存関係を管理し、他のGCPサービスと連携させるSkill。

📜 元の英語説明(参考)

Build serverless functions on Google Cloud Functions. Deploy HTTP and event-driven functions triggered by Pub/Sub, Cloud Storage, and Firestore. Configure runtime settings, manage dependencies, and connect to other GCP services.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Google Cloud Functions上でサーバーレス関数を構築し、Pub/SubやCloud Storageなどのイベントをトリガーに関数を実行、ランタイム設定や依存関係を管理し、他のGCPサービスと連携させるSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o gcp-cloud-functions.zip https://jpskill.com/download/14927.zip && unzip -o gcp-cloud-functions.zip && rm gcp-cloud-functions.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14927.zip -OutFile "$d\gcp-cloud-functions.zip"; Expand-Archive "$d\gcp-cloud-functions.zip" -DestinationPath $d -Force; ri "$d\gcp-cloud-functions.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して gcp-cloud-functions.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → gcp-cloud-functions フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

GCP Cloud Functions

Google Cloud Functions は、イベント駆動型アプリケーションを構築するためのサーバーレス実行環境です。HTTP リクエスト、Pub/Sub メッセージ、Cloud Storage イベント、または Firestore の変更に応答する単一目的の関数を作成します。インフラストラクチャの管理は不要です。

コアコンセプト

  • HTTP Function — HTTP リクエストによってトリガーされ、応答を返します
  • Event Function — クラウドイベント(Pub/Sub、Storage、Firestore)によってトリガーされます
  • Gen 2 — 最新バージョンで、Cloud Run 上に構築され、タイムアウトが長く、同時実行が可能です
  • Trigger — 関数を呼び出すイベントソース
  • Runtime — 言語環境(Node.js、Python、Go、Java など)

HTTP Functions

// index.js — webhook ペイロードを処理する HTTP 関数
const functions = require('@google-cloud/functions-framework');

functions.http('handleWebhook', (req, res) => {
  const { event, data } = req.body;

  if (req.method !== 'POST') {
    return res.status(405).send('Method not allowed');
  }

  console.log(`Received event: ${event}`, data);

  switch (event) {
    case 'order.created':
      // 新しい注文を処理する
      res.json({ status: 'processed', orderId: data.id });
      break;
    default:
      res.json({ status: 'ignored', event });
  }
});
# HTTP 関数をデプロイする (Gen 2)
gcloud functions deploy handle-webhook \
  --gen2 \
  --runtime nodejs20 \
  --region us-central1 \
  --source . \
  --entry-point handleWebhook \
  --trigger-http \
  --allow-unauthenticated \
  --memory 256Mi \
  --timeout 60 \
  --set-env-vars "NODE_ENV=production"

Pub/Sub Triggered Functions

# main.py — Pub/Sub メッセージを処理する
import base64
import json
import functions_framework

@functions_framework.cloud_event
def process_message(cloud_event):
    """Triggered by a Pub/Sub message."""
    data = base64.b64decode(cloud_event.data["message"]["data"]).decode()
    message = json.loads(data)

    print(f"Processing order: {message['order_id']}")

    # 注文を処理する
    result = fulfill_order(message)
    print(f"Order {message['order_id']} fulfilled: {result}")
# Pub/Sub によってトリガーされる関数をデプロイする
gcloud functions deploy process-order \
  --gen2 \
  --runtime python312 \
  --region us-central1 \
  --source . \
  --entry-point process_message \
  --trigger-topic order-events \
  --memory 512Mi \
  --timeout 120 \
  --set-secrets "DATABASE_URL=db-url:latest"

Cloud Storage Triggered Functions

# main.py — アップロードされたファイルを処理する
import functions_framework
from google.cloud import storage, vision

@functions_framework.cloud_event
def process_upload(cloud_event):
    """Triggered when a file is uploaded to Cloud Storage."""
    data = cloud_event.data
    bucket_name = data["bucket"]
    file_name = data["name"]

    if not file_name.lower().endswith(('.jpg', '.png', '.jpeg')):
        print(f"Skipping non-image file: {file_name}")
        return

    print(f"Processing image: gs://{bucket_name}/{file_name}")

    # サムネイルを生成し、OCR を実行するなど
    client = storage.Client()
    bucket = client.bucket(bucket_name)
    blob = bucket.blob(file_name)
    image_data = blob.download_as_bytes()

    # 画像を処理する...
    print(f"Processed {file_name} ({len(image_data)} bytes)")
# Storage によってトリガーされる関数をデプロイする
gcloud functions deploy process-upload \
  --gen2 \
  --runtime python312 \
  --region us-central1 \
  --source . \
  --entry-point process_upload \
  --trigger-event-filters="type=google.cloud.storage.object.v1.finalized" \
  --trigger-event-filters="bucket=my-uploads-bucket" \
  --memory 1Gi \
  --timeout 300

Firestore Triggered Functions

// index.js — Firestore ドキュメントの変更に反応する
const functions = require('@google-cloud/functions-framework');
const { Firestore } = require('@google-cloud/firestore');

functions.cloudEvent('onUserCreated', async (cloudEvent) => {
  const data = cloudEvent.data;
  const newValue = data.value.fields;

  const email = newValue.email.stringValue;
  const name = newValue.name.stringValue;

  console.log(`New user created: ${name} (${email})`);

  // ウェルカムメールを送信し、デフォルト設定を作成するなど
  const db = new Firestore();
  await db.collection('user-settings').doc(data.value.name.split('/').pop()).set({
    theme: 'light',
    notifications: true,
    createdAt: Firestore.FieldValue.serverTimestamp()
  });
});
# Firestore によってトリガーされる関数をデプロイする
gcloud functions deploy on-user-created \
  --gen2 \
  --runtime nodejs20 \
  --region us-central1 \
  --source . \
  --entry-point onUserCreated \
  --trigger-event-filters="type=google.cloud.firestore.document.v1.created" \
  --trigger-event-filters="database=(default)" \
  --trigger-event-filters-path-pattern="document=users/{userId}" \
  --memory 256Mi

Managing Functions

# デプロイされた関数をリストする
gcloud functions list --gen2 --region us-central1
# 関数の詳細を表示する
gcloud functions describe process-order --gen2 --region us-central1
# ログを表示する
gcloud functions logs read process-order --gen2 --region us-central1 --limit 50
# 関数を削除する
gcloud functions delete process-order --gen2 --region us-central1

Local Development

# 関数をローカルで実行する
npx @google-cloud/functions-framework --target=handleWebhook --port=8080
# curl でローカルでテストする
curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{"event":"order.created","data":{"id":"12345"}}'

Best Practices

  • すべての新しい関数に Gen 2 を使用します (パフォーマンスが向上し、同時実行がサポートされます)
  • 実際のニーズに基づいてメモリとタイムアウトを設定します。過剰なプロビジョニングは避けてください
  • 環境変数ではなく、Secret Manager をクレデンシャルに使用します
  • 冪等性のあるハンドラーを実装します。イベントが複数回配信される可能性があります
  • Cloud Logging での可観測性を向上させるために、構造化ロギングを使用します
  • レイテンシの影響を受けやすい関数については、コールドスタートを避けるために min-instances を設定します
  • functions fr
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

GCP Cloud Functions

Google Cloud Functions is a serverless execution environment for building event-driven applications. Write single-purpose functions that respond to HTTP requests, Pub/Sub messages, Cloud Storage events, or Firestore changes — no infrastructure to manage.

Core Concepts

  • HTTP Function — triggered by HTTP requests, returns a response
  • Event Function — triggered by cloud events (Pub/Sub, Storage, Firestore)
  • Gen 2 — latest version, built on Cloud Run, longer timeouts, concurrency
  • Trigger — the event source that invokes the function
  • Runtime — language environment (Node.js, Python, Go, Java, etc.)

HTTP Functions

// index.js — HTTP function that processes webhook payloads
const functions = require('@google-cloud/functions-framework');

functions.http('handleWebhook', (req, res) => {
  const { event, data } = req.body;

  if (req.method !== 'POST') {
    return res.status(405).send('Method not allowed');
  }

  console.log(`Received event: ${event}`, data);

  switch (event) {
    case 'order.created':
      // Process new order
      res.json({ status: 'processed', orderId: data.id });
      break;
    default:
      res.json({ status: 'ignored', event });
  }
});
# Deploy an HTTP function (Gen 2)
gcloud functions deploy handle-webhook \
  --gen2 \
  --runtime nodejs20 \
  --region us-central1 \
  --source . \
  --entry-point handleWebhook \
  --trigger-http \
  --allow-unauthenticated \
  --memory 256Mi \
  --timeout 60 \
  --set-env-vars "NODE_ENV=production"

Pub/Sub Triggered Functions

# main.py — process Pub/Sub messages
import base64
import json
import functions_framework

@functions_framework.cloud_event
def process_message(cloud_event):
    """Triggered by a Pub/Sub message."""
    data = base64.b64decode(cloud_event.data["message"]["data"]).decode()
    message = json.loads(data)

    print(f"Processing order: {message['order_id']}")

    # Process the order
    result = fulfill_order(message)
    print(f"Order {message['order_id']} fulfilled: {result}")
# Deploy Pub/Sub triggered function
gcloud functions deploy process-order \
  --gen2 \
  --runtime python312 \
  --region us-central1 \
  --source . \
  --entry-point process_message \
  --trigger-topic order-events \
  --memory 512Mi \
  --timeout 120 \
  --set-secrets "DATABASE_URL=db-url:latest"

Cloud Storage Triggered Functions

# main.py — process uploaded files
import functions_framework
from google.cloud import storage, vision

@functions_framework.cloud_event
def process_upload(cloud_event):
    """Triggered when a file is uploaded to Cloud Storage."""
    data = cloud_event.data
    bucket_name = data["bucket"]
    file_name = data["name"]

    if not file_name.lower().endswith(('.jpg', '.png', '.jpeg')):
        print(f"Skipping non-image file: {file_name}")
        return

    print(f"Processing image: gs://{bucket_name}/{file_name}")

    # Generate thumbnail, run OCR, etc.
    client = storage.Client()
    bucket = client.bucket(bucket_name)
    blob = bucket.blob(file_name)
    image_data = blob.download_as_bytes()

    # Process image...
    print(f"Processed {file_name} ({len(image_data)} bytes)")
# Deploy Storage triggered function
gcloud functions deploy process-upload \
  --gen2 \
  --runtime python312 \
  --region us-central1 \
  --source . \
  --entry-point process_upload \
  --trigger-event-filters="type=google.cloud.storage.object.v1.finalized" \
  --trigger-event-filters="bucket=my-uploads-bucket" \
  --memory 1Gi \
  --timeout 300

Firestore Triggered Functions

// index.js — react to Firestore document changes
const functions = require('@google-cloud/functions-framework');
const { Firestore } = require('@google-cloud/firestore');

functions.cloudEvent('onUserCreated', async (cloudEvent) => {
  const data = cloudEvent.data;
  const newValue = data.value.fields;

  const email = newValue.email.stringValue;
  const name = newValue.name.stringValue;

  console.log(`New user created: ${name} (${email})`);

  // Send welcome email, create default settings, etc.
  const db = new Firestore();
  await db.collection('user-settings').doc(data.value.name.split('/').pop()).set({
    theme: 'light',
    notifications: true,
    createdAt: Firestore.FieldValue.serverTimestamp()
  });
});
# Deploy Firestore triggered function
gcloud functions deploy on-user-created \
  --gen2 \
  --runtime nodejs20 \
  --region us-central1 \
  --source . \
  --entry-point onUserCreated \
  --trigger-event-filters="type=google.cloud.firestore.document.v1.created" \
  --trigger-event-filters="database=(default)" \
  --trigger-event-filters-path-pattern="document=users/{userId}" \
  --memory 256Mi

Managing Functions

# List deployed functions
gcloud functions list --gen2 --region us-central1
# View function details
gcloud functions describe process-order --gen2 --region us-central1
# View logs
gcloud functions logs read process-order --gen2 --region us-central1 --limit 50
# Delete a function
gcloud functions delete process-order --gen2 --region us-central1

Local Development

# Run function locally
npx @google-cloud/functions-framework --target=handleWebhook --port=8080
# Test locally with curl
curl -X POST http://localhost:8080 \
  -H "Content-Type: application/json" \
  -d '{"event":"order.created","data":{"id":"12345"}}'

Best Practices

  • Use Gen 2 for all new functions (better performance, concurrency support)
  • Set memory and timeout based on actual needs — don't over-provision
  • Use Secret Manager for credentials, not environment variables
  • Implement idempotent handlers — events may be delivered more than once
  • Use structured logging for better observability in Cloud Logging
  • Set min-instances to avoid cold starts for latency-sensitive functions
  • Use the functions framework for local development and testing
  • Keep functions focused — one function, one purpose