Connecting the Dots in Google Cloud: Understanding Serverless VPC Access Connector

Connecting the Dots in Google Cloud: Understanding Serverless VPC Access Connector

In the modern cloud-native ecosystem, serverless applications are gaining immense popularity due to their simplicity, scalability, and reduced operational overhead. However, serverless compute environments like Cloud Functions, Cloud Run, and App Engine Standard are often isolated from private resources in a Virtual Private Cloud (VPC), such as Cloud SQL, Memorystore, or internal services.

That’s where Serverless VPC Access Connector comes in — bridging the gap between your serverless workloads and private VPC resources.

What is Serverless VPC Access?

Serverless VPC Access is a Google Cloud feature that enables serverless compute environments to connect securely and privately to resources hosted inside your VPC network. By default, these serverless services operate in isolated environments without access to internal IPs. The connector opens a door to communicate with databases, services, and other resources within a VPC using internal IP addressing — all while maintaining security and performance.

Why is it Needed?

Serverless products are powerful, but they come with limitations in connectivity:

  • Cloud SQL access without public IPs
  • Calling internal microservices hosted on Compute Engine or GKE
  • Accessing Redis (Memorystore) over private IP
  • Interfacing with legacy on-premises systems via VPN/Interconnect

Without VPC Access, serverless apps can’t talk directly to these internal systems. The Serverless VPC Access Connector solves this challenge by creating a secure bridge between your serverless compute and your private infrastructure.

How It Works

The Serverless VPC Access Connector is a managed component deployed in a specific VPC subnet. When a serverless service needs to talk to private resources, it uses this connector as the egress path for all private IP traffic.

Here’s a high-level breakdown:

  1. You create a VPC Access Connector in a specific region and subnet.
  2. You configure your Cloud Run, Cloud Functions, or App Engine service to use the connector.
  3. Outbound traffic from your serverless service to RFC 1918 (private IP) addresses is routed through this connector into your VPC network.
  4. Traffic destined for public internet remains unaffected unless you force all egress through the connector.

The connector doesn’t handle inbound traffic — it’s solely for outbound communication from your serverless workloads to your private network.

Key Configuration Aspects

When creating a connector, you must specify:

  • Region: It must match the region of your serverless service.
  • VPC Network: The private network the connector should attach to.
  • IP Range: A /28 to /23 CIDR block used by the connector to provision virtual interfaces.

After the connector is deployed, you configure your serverless service with a reference to the connector. For example, in Cloud Run, this is done via the --vpc-connector flag.

Use Cases

Some typical use cases for Serverless VPC Access include:

  • Cloud Run accessing Cloud SQL using private IP for faster, more secure connections.
  • Cloud Functions querying a backend API hosted on a Compute Engine instance with internal IP only.
  • App Engine Standard fetching configuration data from an internal-only GKE service.
  • Integration with on-prem systems via Cloud VPN or Interconnect without exposing those systems publicly.

Limitations & Considerations

While the connector is powerful, it has a few things to keep in mind:

  • Region-bound: Your connector must be in the same region as your service. For multi-region deployments, you may need multiple connectors.
  • Cost: Usage of the connector incurs charges based on data processed and number of instances.
  • No inbound routing: It only handles traffic going out from serverless to VPC, not vice versa.
  • Scaling constraints: Make sure your IP range is big enough to handle expected throughput and concurrency.
  • Performance tuning: Use the connector.max-instances setting to manage throughput under load.

Monitoring and Troubleshooting

Google Cloud provides monitoring tools via Cloud Monitoring and Logging. You can view metrics like:

  • Connector usage
  • Traffic throughput
  • Instance scaling behavior
  • Error rates and retry attempts

You should also enable VPC flow logs on the subnet used by the connector for more detailed network analysis.

Best Practices

To get the most out of Serverless VPC Access, consider these best practices:

  • Plan your IP range carefully to avoid overlap and ensure enough scale.
  • Isolate connectors per environment (e.g., dev, staging, prod) for better control and monitoring.
  • Use private IP for Cloud SQL or Memorystore when possible for faster, more secure connections.
  • Implement IAM and firewall rules to restrict access to only what’s needed.
  • Use Cloud NAT if needed for internet-bound traffic from the VPC if your connector routes everything.


Lab Integration: Connecting Cloud Run Functions to Memorystore using Serverless VPC Access


  • Setup project

 PROJECT_ID=$(gcloud config get-value project)
 REGION=us-west1        

  • Enable all necessary services

gcloud services enable \
  artifactregistry.googleapis.com \
  cloudfunctions.googleapis.com \
  cloudbuild.googleapis.com \
  eventarc.googleapis.com \
  run.googleapis.com \
  logging.googleapis.com \
  pubsub.googleapis.com \
  redis.googleapis.com \
  vpcaccess.googleapis.com        

  • Set up a Memorystore for Redis instance

REDIS_INSTANCE=customerdb

gcloud redis instances create $REDIS_INSTANCE \
 --size=2 --region=$REGION \
 --redis-version=redis_6_x        


Article content

  • Create VPC connector

  1. Navigate to VPC Networks
  2. select Serverless VPC access
  3. Click on Create connector(create according to your network)


Article content

  • Deploy cloud run function with VPC connector

gcloud functions deploy python-pubsub-function \
 --runtime=python310 \
 --region=$REGION \
 --source=. \
 --entry-point=addToRedis \
 --trigger-topic=$TOPIC \
 --vpc-connector projects/$PROJECT_ID/locations/$REGION/connectors/test-connector \
 --set-env-vars REDISHOST=$REDIS_IP,REDISPORT=$REDIS_PORT        
import os
import base64
import json
import redis
import functions_framework

redis_host = os.environ.get('REDISHOST', 'localhost')
redis_port = int(os.environ.get('REDISPORT', 6379))
redis_client = redis.StrictRedis(host=redis_host, port=redis_port)

# Triggered from a message on a Pub/Sub topic.
@functions_framework.cloud_event
def addToRedis(cloud_event):
    # The Pub/Sub message data is stored as a base64-encoded string in the cloud_event.data property
    # The expected value should be a JSON string.
    json_data_str = base64.b64decode(cloud_event.data["message"]["data"]).decode()
    json_payload = json.loads(json_data_str)
    response_data = ""
    if json_payload and 'id' in json_payload:
        id = json_payload['id']
        data = redis_client.set(id, json_data_str)
        response_data = redis_client.get(id)
        print(f"Added data to Redis: {response_data}")
    else:
        print("Message is invalid, or missing an 'id' attribute")        


Article content

Final Thoughts

Google Cloud’s Serverless VPC Access Connector is a vital tool for developers building modern, scalable applications that require hybrid connectivity between serverless compute and private infrastructure. Whether you're accessing Cloud SQL, integrating with legacy systems, or interacting with backend APIs, this feature provides the control, security, and reliability your apps need — without sacrificing the benefits of serverless development.

In a world where microservices and hybrid workloads are the norm, Serverless VPC Access Connector ensures that your architecture remains connected, secure, and future-ready.

To view or add a comment, sign in

More articles by Chinmaya Kumar Biswal

Insights from the community

Others also viewed

Explore topics