Skip to content
cloudflare-vpc-services logo

Cloudflare VPC Services

cloudflare-vpc-services

Diagnose and create Cloudflare VPC Services for Workers to access private APIs in AWS, Azure, GCP, or on-premise networks. Use when troubleshooting dns_error, configuring cloudflared tunnels, setting up VPC service bindings, or routing Workers to internal services.

SKILL.md

Full skill instructions

Cloudflare VPC Services

Enable Workers to securely access private APIs and services through encrypted tunnels without public internet exposure.

⚠️ BEFORE YOU START

This skill prevents 5 common errors and saves ~60% tokens.

MetricWithout SkillWith Skill
Setup Time45+ min10 min
Common Errors50
Token Usage~8000~3000

Known Issues This Skill Prevents

  1. dns_error from outdated cloudflared version or wrong protocol
  2. Requests leaving VPC due to using public hostnames instead of internal
  3. Port mismatch - fetch() port is ignored, service config port is used
  4. Missing absolute URLs in fetch() calls
  5. Incorrect tunnel ID or service binding configuration

Quick Start

Step 1: Verify Tunnel Requirements

# Check cloudflared version on remote infrastructure (K8s, EC2, etc.)
# Must be 2025.7.0 or later
cloudflared --version

# Verify QUIC protocol is configured (not http2)
# Check tunnel config or Cloudflare dashboard

Why this matters: Workers VPC requires cloudflared 2025.7.0+ with QUIC protocol. Older versions or http2 protocol cause dns_error.

Step 2: Create VPC Service

# Use Cloudflare API or dashboard to create VPC service
# See templates/​vpc-service-ip.json or templates/​vpc-service-hostname.json

Why this matters: The VPC service defines the actual target (IP/​hostname) that the tunnel routes to. The fetch() URL only sets Host header and SNI.

Step 3: Configure Wrangler Binding

// wrangler.jsonc
{
  "vpc_services": [
    {
      "binding": "PRIVATE_API",
      "service_id": "<YOUR_SERVICE_ID>",
      "remote": true
    }
  ]
}

Why this matters: The binding name becomes the environment variable used in Worker code: env.PRIVATE_API.fetch().

Critical Rules

✅ Always Do

  • ✅ Use absolute URLs with protocol, host, and path in fetch()
  • ✅ Use internal VPC hostnames, not public endpoints
  • ✅ Ensure cloudflared is 2025.7.0+ with QUIC protocol
  • ✅ Allow UDP port 7844 outbound for QUIC connections

❌ Never Do

  • ❌ Use port numbers in fetch() URL (they're ignored)
  • ❌ Use public hostnames for services inside VPC
  • ❌ Assume http2 protocol works (only QUIC is supported)
  • ❌ Use relative URLs in fetch()

Common Mistakes

❌ Wrong:

// Port is ignored, relative URL fails
const response = await env.VPC_SERVICE.fetch("/​api/​users:8080");

✅ Correct:

// Absolute URL, port configured in VPC service
const response = await env.VPC_SERVICE.fetch("https://internal-api.company.local/​api/​users");

Why: The VPC service configuration determines actual routing. The fetch() URL only populates the Host header and SNI value.

Known Issues Prevention

IssueRoot CauseSolution
dns_errorcloudflared < 2025.7.0 or http2 protocolUpdate cloudflared, configure QUIC, allow UDP 7844
Requests go to public internetUsing public hostname in fetch()Use internal VPC hostname
Connection refusedWrong port in VPC service configConfigure correct http_port/​https_port in service
TimeoutTunnel not running or wrong tunnel_idVerify tunnel status, check tunnel_id
404 errorsIncorrect path routingVerify internal service path matches fetch() path

Configuration Reference

wrangler.jsonc

{
  "name": "my-worker",
  "main": "src/​index.ts",
  "compatibility_date": "2024-01-01",
  "vpc_services": [
    {
      "binding": "PRIVATE_API",
      "service_id": "daf43e8c-a81a-4242-9912-4a2ebe4fdd79",
      "remote": true
    },
    {
      "binding": "PRIVATE_DATABASE",
      "service_id": "453b6067-1327-420d-89b3-2b6ad16e6551",
      "remote": true
    }
  ]
}

Key settings:

  • binding: Environment variable name for accessing the service
  • service_id: UUID from VPC service creation
  • remote: Must be true for VPC services

Common Patterns

Basic GET Request

export default {
  async fetch(request, env) {
    const response = await env.PRIVATE_API.fetch(
      "https://internal-api.company.local/​users"
    );
    return response;
  }
};

POST with Authentication

const response = await env.PRIVATE_API.fetch(
  "https://internal-api.company.local/​users",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/​json",
      Authorization: `Bearer ${env.API_TOKEN}`
    },
    body: JSON.stringify({ name: "John", email: "[email protected]" })
  }
);

API Gateway with Path Routing

export default {
  async fetch(request, env) {
    const url = new URL(request.url);

    if (url.pathname.startsWith('/​api/​users')) {
      return env.USER_SERVICE.fetch(
        `https://user-api.internal${url.pathname}`
      );
    } else if (url.pathname.startsWith('/​api/​orders')) {
      return env.ORDER_SERVICE.fetch(
        `https://orders-api.internal${url.pathname}`
      );
    }

    return new Response('Not Found', { status: 404 });
  }
};

Bundled Resources

Templates

Located in templates/:

Copy these templates as starting points for your implementation.

Scripts

Located in scripts/:

References

Located in references/:

Dependencies

Required

PackageVersionPurpose
wranglerlatestDeploy Workers with VPC bindings
cloudflared2025.7.0+Tunnel daemon (on remote infrastructure)

Optional

PackageVersionPurpose
@cloudflare/​workers-typeslatestTypeScript types for Workers

Official Documentation

Troubleshooting

dns_error when calling VPC service

Symptoms: Worker returns dns_error when calling env.VPC_SERVICE.fetch()

Solution:

  1. Update cloudflared to 2025.7.0+ on remote infrastructure
  2. Configure QUIC protocol (not http2)
  3. Allow UDP port 7844 outbound

Requests going to public internet

Symptoms: Logs show requests hitting public endpoints instead of internal

Solution:

// Use internal hostname
const response = await env.VPC_SERVICE.fetch(
  "https://internal-api.vpc.local/​endpoint"  // Internal
  // NOT "https://api.company.com/​endpoint"   // Public
);

Connection timeout

Symptoms: Requests hang and eventually timeout

Solution:

  1. Verify tunnel is running: check cloudflared logs
  2. Verify tunnel_id matches in VPC service config
  3. Check network connectivity from tunnel to target

Setup Checklist

Before using this skill, verify:

  • cloudflared 2025.7.0+ deployed on remote infrastructure
  • QUIC protocol configured (not http2)
  • UDP port 7844 outbound allowed
  • VPC service created with correct tunnel_id
  • wrangler.jsonc has vpc_services binding
  • Using internal hostnames (not public endpoints)
  • Using absolute URLs in fetch() calls

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View