Google CloudCloud FunctionsServerless

google_cloudfunctions2_function cost estimation

A serverless function (2nd gen, Cloud Run-based). Billed per invocation, vCPU-time, memory-time, and outbound networking.

A google_cloudfunctions2_function runs a serverless function. 2nd generation Cloud Functions are built on Cloud Run under the hood, so the pricing model is identical to Cloud Run.

Pricing components:

Invocations: $0.40 per million invocations. First 2 million per month are free at the project level.

vCPU-time: billed per vCPU-second during request handling, rounded to 100ms. Rate scales with vCPU allocation (the function's CPU setting). Free tier: 360,000 vCPU-seconds/month.

Memory-time: billed per GB-second during request handling. Free tier: 180,000 GB-seconds/month.

Networking egress: standard GCP egress rates apply for bytes returned to clients.

Always-allocated CPU (available_cpu set on the function with explicit CPU value, or via instance-based billing): the CPU is always allocated, not just during request handling. Higher cost but better cold-start performance.

1st generation Cloud Functions (google_cloudfunctions_function) had a slightly different pricing model with separate compute price tiers. 1st gen still works but new deployments should use 2nd gen.

c3x estimates Cloud Functions from c3x-usage.yml's monthly_invocations and average_duration_ms on the function. Without that, the function shows the per-unit rates.

Terraform example

A minimal but realistic configuration that C3X can estimate.

resource "google_cloudfunctions2_function" "processor" {
  name     = "event-processor"
  location = "us-central1"

  build_config {
    runtime     = "python311"
    entry_point = "process_event"

    source {
      storage_source {
        bucket = google_storage_bucket.source.name
        object = google_storage_bucket_object.source.name
      }
    }
  }

  service_config {
    max_instance_count               = 100
    min_instance_count               = 0
    available_memory                 = "512M"
    available_cpu                    = "1"
    timeout_seconds                  = 60
    max_instance_request_concurrency = 80
    ingress_settings                 = "ALLOW_INTERNAL_ONLY"
  }
}

Pricing dimensions

What you actually pay for when you provision google_cloudfunctions2_function.

DimensionUnitWhat's being charged
Invocationsper 1M invocationsEach function call. First 2M/month free at project level.
$0.40/1M invocations
vCPU timeper vCPU-secondBilled during request handling, rounded to nearest 100ms. First 360,000 vCPU-seconds/month free.
$0.000024/vCPU-second
Memory timeper GB-secondBilled during request handling. First 180,000 GB-seconds/month free.
$0.0000025/GB-second
Outbound networkingper GBBytes returned to clients. Standard GCP egress rates.
Always-allocated CPU (instance-based)per vCPU-second + per GB-secondHigher rate but CPU is always allocated, eliminating cold starts.

Optimization tips

Common ways to reduce google_cloudfunctions2_function cost without changing the workload.

Right-size memory and CPU

Workload-dependent

available_memory and available_cpu directly drive per-second costs. A function requesting 512 MB / 1 vCPU but actually using 200 MB / 0.5 vCPU is overpaying by 2-3x.

Set min_instance_count = 0 for cost

Cost during idle

Scale-to-zero is free during idle periods. For latency-sensitive functions, set min_instance_count = 1 (always-on, billed continuously). Otherwise, zero.

Increase max_instance_request_concurrency

Workload-dependent

Cloud Functions 2nd gen can handle multiple concurrent requests per instance (default 80). Higher concurrency means fewer instances per request volume, lower total vCPU-seconds.

Use CPU-throttled-when-idle for spiky workloads

Up to 70% during idle

The default (cpu_idle = true) reduces CPU between requests to nearly zero, charging only for active request time. Right for functions with idle periods.

Take advantage of free tier

Up to 100% for small workloads

Cloud Functions free tier (2M invocations + 360,000 vCPU-seconds + 180,000 GB-seconds) covers many smaller workloads entirely. Stay below for free production use.

FAQ

Should I use 1st gen or 2nd gen?

2nd gen. It's built on Cloud Run, supports longer timeouts (60min vs 9min), higher concurrency per instance (up to 1000), and longer support lifecycle. 1st gen is legacy.

What's the difference between Cloud Functions 2nd gen and Cloud Run?

Under the hood, Cloud Functions 2nd gen IS Cloud Run with extra automation (source code build, trigger wiring). The pricing model is identical. Choose Functions when you want simpler deployment of a single function; Cloud Run for more flexibility (full container, custom build, more endpoints).

How does c3x estimate Cloud Functions?

Same as Cloud Run. Add monthly_invocations and average_duration_ms to c3x-usage.yml on the function. c3x computes vCPU-seconds and GB-seconds from the available_cpu and available_memory attributes.

Does VPC connector add cost?

Yes. A Serverless VPC Access connector (google_vpc_access_connector) charges per instance-hour for the connector itself plus per-GB throughput. c3x estimates connectors independently.

Related resources

Estimate this resource in your own Terraform

Free, open source, no API key. C3X parses your Terraform and shows line-item cost for every resource, including google_cloudfunctions2_function.