cloudthinker-ai/CloudSkills / skills/connections/gcp-cloud-functions
gcp-cloud-functions
UnverifiedUse when working with Gcp Cloud Functions — google Cloud Functions management, execution analysis, scaling configuration, event trigger inspection, and runtime diagnostics via gcloud CLI.
Cloud Functions Skill
Manage and analyze Google Cloud Functions using gcloud functions commands.
Discovery-First Rule
ALWAYS discover before acting. Never assume function names, regions, runtimes, or trigger types.
# Discover all functions (v2 and v1)
gcloud functions list --format=json \
| jq '[.[] | {name: .name, status: .state // .status, runtime: .buildConfig.runtime // .runtime, region: .name | split("/") | .[3], generation: (if .buildConfig then "v2" else "v1" end), entryPoint: .buildConfig.entryPoint // .entryPoint}]'
Parallel Execution Requirement
ALL independent operations MUST run in parallel using background jobs (&) and wait.
for fn in $(gcloud functions list --format="value(name)" --uri); do
{
gcloud functions describe "$fn" --format=json
} &
done
wait
Helper Functions
# Get function details (v2)
get_function_v2() {
local name="$1" region="$2"
gcloud functions describe "$name" --region="$region" --gen2 --format=json \
| jq '{name: .name, state: .state, runtime: .buildConfig.runtime, entryPoint: .buildConfig.entryPoint, trigger: .eventTrigger // "HTTP", serviceConfig: {memory: .serviceConfig.availableMemory, timeout: .serviceConfig.timeoutSeconds, maxInstances: .serviceConfig.maxInstanceCount, minInstances: .serviceConfig.minInstanceCount, concurrency: .serviceConfig.maxInstanceRequestConcurrency, serviceAccountEmail: .serviceConfig.serviceAccountEmail}}'
}
# Get function logs
get_function_logs() {
local name="$1" region="$2" limit="${3:-50}"
gcloud functions logs read "$name" --region="$region" --gen2 --limit="$limit" --format=json
}
# Get execution metrics via Cloud Monitoring
get_function_metrics() {
local project="$1" function_name="$2"
gcloud monitoring time-series list \
--filter="metric.type=\"cloudfunctions.googleapis.com/function/execution_count\" AND resource.labels.function_name=\"$function_name\"" \
--interval-start-time="$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" \
--format=json
}
# List event triggers
list_event_triggers() {
local region="$1"
gcloud functions list --region="$region" --format=json \
| jq '[.[] | select(.eventTrigger) | {name: .name | split("/") | last, eventType: .eventTrigger.eventType, resource: .eventTrigger.pubsubTopic // .eventTrigger.eventFilters[0].value, retryPolicy: .eventTrigger.retryPolicy}]'
}
Common Operations
1. Function Inventory and Health
regions=$(gcloud functions regions list --format="value(name)")
for region in $regions; do
{
functions=$(gcloud functions list --region="$region" --format=json 2>/dev/null)
if [ "$(echo "$functions" | jq length)" -gt 0 ]; then
echo "$functions" | jq '[.[] | {name: .name | split("/") | last, state: .state // .status, runtime: .buildConfig.runtime // .runtime, region: "'"$region"'"}]'
fi
} &
done
wait
2. Execution Analysis
# Recent executions and errors from logs
gcloud functions logs read "$FUNCTION" --region="$REGION" --gen2 --limit=100 --format=json \
| jq '[.[] | select(.severity == "ERROR")] | length as $errors | {totalLogs: length, errors: $errors}'
# Execution count and latency via monitoring
gcloud monitoring time-series list \
--filter="metric.type=\"cloudfunctions.googleapis.com/function/execution_times\" AND resource.labels.function_name=\"$FUNCTION\"" \
--interval-start-time="$(date -u -v-24H +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '24 hours ago' +%Y-%m-%dT%H:%M:%SZ)" \
--format=json
3. Scaling Configuration
# Check instance limits and concurrency (v2)
gcloud functions describe "$FUNCTION" --region="$REGION" --gen2 --format=json \
| jq '{minInstances: .serviceConfig.minInstanceCount, maxInstances: .serviceConfig.maxInstanceCount, concurrency: .serviceConfig.maxInstanceRequestConcurrency, availableMemory: .serviceConfig.availableMemory, timeout: .serviceConfig.timeoutSeconds, availableCpu: .serviceConfig.availableCpu}'
4. Event Trigger Configuration
# List all event-triggered functions
gcloud functions list --format=json \
| jq '[.[] | select(.eventTrigger) | {name: .name | split("/") | last, eventType: .eventTrigger.eventType, triggerRegion: .eventTrigger.triggerRegion, retryPolicy: .eventTrigger.retryPolicy, channel: .eventTrigger.channel, filters: .eventTrigger.eventFilters}]'
5. Build and Deployment Status
# Check build details
gcloud functions describe "$FUNCTION" --region="$REGION" --gen2 --format=json \
| jq '{buildConfig: {runtime: .buildConfig.runtime, entryPoint: .buildConfig.entryPoint, source: .buildConfig.source, buildServiceAccount: .buildConfig.serviceAccount}, updateTime: .updateTime, createTime: .createTime}'
# Check recent deployments
gcloud builds list --filter="substitutions.FUNCTION_NAME=$FUNCTION" --limit=5 --format=json \
| jq '[.[] | {id: .id, status: .status, startTime: .startTime, duration: .duration}]'
Output Format
Present results as a structured report:
Gcp Cloud Functions Report
══════════════════════════
Resources discovered: [count]
Resource Status Key Metric Issues
──────────────────────────────────────────────
[name] [ok/warn] [value] [findings]
Summary: [total] resources | [ok] healthy | [warn] warnings | [crit] critical
Action Items: [list of prioritized findings]
Target ≤50 lines of output. Use tables for multi-resource comparisons.
Anti-Hallucination Rules
- NEVER assume resource names — always discover via CLI/API in Phase 1 before referencing in Phase 2.
- NEVER fabricate metric names or dimensions — verify against the service documentation or
--helpoutput. - NEVER mix CLI commands between service versions — confirm which version/API you are targeting.
- ALWAYS use the discovery → verify → analyze chain — every resource referenced must have been discovered first.
- ALWAYS handle empty results gracefully — an empty response is valid data, not an error to retry.
Counter-Rationalizations
| Shortcut | Counter | Why |
|---|---|---|
| "I'll skip discovery and check known resources" | Always run Phase 1 discovery first | Resource names change, new resources appear — assumed names cause errors |
| "The user only asked for a quick check" | Follow the full discovery → analysis flow | Quick checks miss critical issues; structured analysis catches silent failures |
| "Default configuration is probably fine" | Audit configuration explicitly | Defaults often leave logging, security, and optimization features disabled |
| "Metrics aren't needed for this" | Always check relevant metrics when available | API/CLI responses show current state; metrics reveal trends and intermittent issues |
| "I don't have access to that" | Try the command and report the actual error | Assumed permission failures prevent useful investigation; actual errors are informative |
Common Pitfalls
- v1 vs v2: Cloud Functions v2 uses
--gen2flag. Commands differ between versions. Check the generation before running describe/update. - Cold starts: Min instances of 0 means cold starts on first invocation. Set
minInstanceCountfor latency-sensitive functions. - Concurrency (v2 only): v2 functions support concurrent requests per instance. v1 processes one request per instance. Check
maxInstanceRequestConcurrency. - Timeout limits: v1 max timeout is 540s, v2 max is 3600s for event-driven and 3600s for HTTP. Check runtime for long-running operations.
- VPC connector: Functions in a VPC connector route all egress through the VPC. Check connector throughput settings to avoid bottlenecks.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 117k | Updated | Claude CodeCodex | Unverified | Install |