Guide · AWS VPC Lattice · Networking
AWS VPC Lattice for MCP Servers — Service-to-Service Networking Without VPC Peering
AWS VPC Lattice is a managed application networking layer that lets MCP servers call backend services across VPC boundaries — without VPC peering, transit gateways, or PrivateLink boilerplate. When your MCP server in one VPC needs to reach a data-access service or authentication microservice in another VPC (or another AWS account), VPC Lattice provides a consistent HTTP/HTTPS endpoint, service-level auth policies, and built-in observability. This guide covers the core concepts, the @aws-sdk/client-vpc-lattice SDK, and how to wire up a service network from scratch in Node.js.
TL;DR
VPC Lattice has three building blocks: a Service Network (the shared fabric — VPCs and services join it), a Service (your endpoint — has a DNS name, a listener, and an optional auth policy), and a Target Group (the backend — EC2 instances, Fargate task IPs, Lambda functions, or an ALB). Callers in an associated VPC reach services at a .on.aws DNS name automatically, with no route table changes. Auth is opt-in: set authType: "AWS_IAM" and callers must sign requests with SigV4.
Why VPC Lattice instead of VPC peering or PrivateLink
The classic options for cross-VPC communication each come with trade-offs that hurt MCP server teams:
| Mechanism | CIDR overlap? | Per-service setup | Auth built-in? | Works cross-account? |
|---|---|---|---|---|
| VPC Peering | Blocked by overlapping CIDRs | Route tables in every VPC | No — SGs only | Yes, but complex route management |
| Transit Gateway | CIDRs must not overlap | Attachments + route tables | No | Yes, via peering or RAM |
| PrivateLink | Works with overlapping CIDRs | NLB + endpoint service per VPC pair | No | Yes, requires consumer accept |
| VPC Lattice | Works with overlapping CIDRs | One service network for all services | Yes — IAM SigV4 | Yes, via RAM sharing |
For MCP server deployments, VPC Lattice matters most when you need many services accessible from one VPC (MCP server VPC), all secured with IAM. Peering or PrivateLink requires per-service NLBs and route entries; Lattice requires one service network join and then you can reach any associated service by DNS name.
Three building blocks
Understanding the object model is the prerequisite to everything else:
- Service Network
- A logical fabric that VPCs and services join. Think of it as the meeting room. When a VPC associates with the service network, DNS resolution for
.vpc-lattice-svcs.{region}.on.awsdomains is wired in automatically. When a service associates with the service network, consumers in associated VPCs can reach it. A service network can have an auth policy (enforced before any service-level policy). Auth type defaults toNONE; setAWS_IAMto require SigV4. - Service
- Represents one logical endpoint — your MCP data-access service, your registry service, etc. Each service gets a stable DNS name like
{service-name}-{random}.{service-network-name}-{random}.vpc-lattice-svcs.{region}.on.aws. Services have listeners (HTTP on port 80, or HTTPS on 443 with an ACM certificate) and routing rules (forward to a target group based on path prefix, header, or method). Services can be in a different AWS account from the service network. - Target Group
- The backend behind a service's routing rule. VPC Lattice supports four target types:
INSTANCE(EC2 instance IDs),IP(IPv4/IPv6 — use this for Fargate tasks),LAMBDA(Lambda function ARN or alias), andALB(Application Load Balancer ARN). Targets are registered viaRegisterTargetsCommandfor INSTANCE and IP types.
SDK installation
npm install @aws-sdk/client-vpc-lattice
The VPC Lattice client is regional — instantiate it in the same region as your resources:
import { VpcLatticeClient } from "@aws-sdk/client-vpc-lattice";
const lattice = new VpcLatticeClient({ region: "us-east-1" });
Creating a service network
CreateServiceNetworkCommand creates the shared fabric. The key choice is authType: NONE means no request signing required; AWS_IAM means every caller must sign with SigV4 and the network-level auth policy is evaluated.
import {
VpcLatticeClient,
CreateServiceNetworkCommand,
} from "@aws-sdk/client-vpc-lattice";
const lattice = new VpcLatticeClient({ region: "us-east-1" });
const network = await lattice.send(new CreateServiceNetworkCommand({
name: "mcp-platform",
authType: "AWS_IAM", // require SigV4 on every call
tags: { Environment: "production", Team: "platform" },
}));
console.log("Service network ARN:", network.arn);
// arn:aws:vpc-lattice:us-east-1:123456789012:servicenetwork/sn-0abc123def456789a
The service network name must be unique in the account and region. Names are immutable — delete and recreate to rename.
Creating a target group
Before creating a service you need a target group for it to route to. For an MCP data-access service running as Fargate tasks (IP targets), use type IP:
import { CreateTargetGroupCommand } from "@aws-sdk/client-vpc-lattice";
const tg = await lattice.send(new CreateTargetGroupCommand({
name: "mcp-data-service-tg",
type: "IP",
config: {
vpcIdentifier: "vpc-0abc12345def67890", // VPC where Fargate tasks run
protocol: "HTTP",
port: 3000,
protocolVersion: "HTTP1",
healthCheck: {
enabled: true,
path: "/health",
protocol: "HTTP",
port: 3000,
healthyThresholdCount: 2,
unhealthyThresholdCount: 3,
intervalSeconds: 30,
timeoutSeconds: 5,
statusCodes: { statusCodeRange: "200-299" },
matchers: { httpCode: "200-299" },
},
},
}));
console.log("Target group ARN:", tg.arn);
For Lambda targets, omit config.vpcIdentifier, config.port, and the health check — VPC Lattice invokes Lambda directly:
const lambdaTg = await lattice.send(new CreateTargetGroupCommand({
name: "mcp-auth-service-tg",
type: "LAMBDA",
}));
Registering targets
For IP and INSTANCE target groups, explicitly register each target. For LAMBDA and ALB types you register the ARN once and VPC Lattice handles routing:
import { RegisterTargetsCommand } from "@aws-sdk/client-vpc-lattice";
// Register Fargate task ENI IPs
await lattice.send(new RegisterTargetsCommand({
targetGroupIdentifier: tg.id,
targets: [
{ id: "10.0.1.42", port: 3000 },
{ id: "10.0.2.17", port: 3000 },
],
}));
// Register Lambda function (use function ARN or alias ARN)
import { RegisterTargetsCommand } from "@aws-sdk/client-vpc-lattice";
await lattice.send(new RegisterTargetsCommand({
targetGroupIdentifier: lambdaTg.id,
targets: [
{ id: "arn:aws:lambda:us-east-1:123456789012:function:mcp-auth-service" },
],
}));
Creating a service with a listener and rule
A service gets its DNS name when created. Listeners define the protocol and port. Rules define how to route incoming requests to target groups:
import {
CreateServiceCommand,
CreateListenerCommand,
CreateRuleCommand,
} from "@aws-sdk/client-vpc-lattice";
// Create the service
const svc = await lattice.send(new CreateServiceCommand({
name: "mcp-data-service",
authType: "AWS_IAM", // service-level auth (layered on top of network auth)
tags: { Team: "platform" },
}));
console.log("Service ARN:", svc.arn);
// DNS assigned after VPC association (see below)
// Create HTTP listener on port 80
const listener = await lattice.send(new CreateListenerCommand({
serviceIdentifier: svc.id,
name: "http-listener",
protocol: "HTTP",
port: 80,
defaultAction: {
// Default: 404 for unmatched requests
fixedResponse: { statusCode: 404 },
},
}));
// Create routing rule: forward all paths to the target group
await lattice.send(new CreateRuleCommand({
serviceIdentifier: svc.id,
listenerIdentifier: listener.id,
name: "forward-all",
priority: 10, // lower number = higher priority
match: {
httpMatch: {
pathMatch: {
match: { prefix: "/" }, // match every path
caseSensitive: false,
},
},
},
action: {
forward: {
targetGroups: [
{ targetGroupIdentifier: tg.id, weight: 100 },
],
},
},
}));
Associating the VPC and service with the service network
Two separate association calls wire everything together. The VPC association makes all services in the network reachable from that VPC. The service association makes the specific service discoverable in the network:
import {
CreateServiceNetworkVpcAssociationCommand,
CreateServiceNetworkServiceAssociationCommand,
GetServiceCommand,
} from "@aws-sdk/client-vpc-lattice";
// Associate the caller's VPC (where the MCP server runs) with the network
const vpcAssoc = await lattice.send(new CreateServiceNetworkVpcAssociationCommand({
serviceNetworkIdentifier: network.id,
vpcIdentifier: "vpc-0mcp1server2vpc34", // MCP server's VPC
securityGroupIds: [
"sg-0abc123outboundonly", // SG controlling traffic from VPC into Lattice
],
}));
console.log("VPC association status:", vpcAssoc.status);
// ACTIVE after a few seconds; poll with GetServiceNetworkVpcAssociationCommand
// Associate the service with the network
const svcAssoc = await lattice.send(new CreateServiceNetworkServiceAssociationCommand({
serviceNetworkIdentifier: network.id,
serviceIdentifier: svc.id,
}));
console.log("Service association status:", svcAssoc.status);
// ACTIVE after a few seconds; check svcAssoc.dnsEntry.domainName for the hostname
Once ACTIVE, retrieve the service's DNS name and use it from any EC2 instance, ECS task, or Lambda in the associated VPC:
const svcDetails = await lattice.send(new GetServiceCommand({
serviceIdentifier: svc.id,
}));
console.log("Call this from your MCP server:", svcDetails.dnsEntry?.domainName);
// e.g. mcp-data-service-0a1b2c.mcp-platform-3d4e5f.vpc-lattice-svcs.us-east-1.on.aws
Security group configuration for the VPC association
The security group attached to the VPC association controls traffic from the VPC into the VPC Lattice fabric. VPC Lattice injects a managed prefix list (pl-xxxxxxxx for com.amazonaws.{region}.vpc-lattice) that you should allow in the outbound rule, plus the IPv6 equivalent:
# Get the VPC Lattice managed prefix list ID
aws ec2 describe-managed-prefix-lists \
--filters "Name=prefix-list-name,Values=com.amazonaws.us-east-1.vpc-lattice" \
--query "PrefixLists[0].PrefixListId" \
--output text
# pl-0abc123def456789a
# Your security group outbound rules (via IaC or CLI):
# Allow TCP 80 and 443 to the Lattice managed prefix list
# This SG is what you pass to CreateServiceNetworkVpcAssociationCommand
On the target side (the ECS service or EC2 instances running your backend), add an inbound rule allowing traffic from the VPC Lattice prefix list on the backend port (3000 in the example above). Unlike PrivateLink, there are no per-service ENIs — a single prefix list covers all Lattice traffic in the region.
Calling the service from an MCP server tool
When auth type is NONE, calling the service is a plain HTTPS request to the DNS name. When auth is AWS_IAM, you must sign with SigV4 (service name vpc-lattice-svcs). With the AWS SDK's credential chain, signing is straightforward:
import { SignatureV4 } from "@aws-sdk/signature-v4";
import { Sha256 } from "@aws-crypto/sha256-js";
import { defaultProvider } from "@aws-sdk/credential-provider-node";
import https from "https";
const signer = new SignatureV4({
credentials: defaultProvider(),
region: "us-east-1",
service: "vpc-lattice-svcs",
sha256: Sha256,
});
const url = new URL("http://mcp-data-service-0a1b2c.mcp-platform-3d4e5f.vpc-lattice-svcs.us-east-1.on.aws/data/items");
const signed = await signer.sign({
method: "GET",
hostname: url.hostname,
path: url.pathname + url.search,
headers: { host: url.hostname },
protocol: "https:",
});
// signed.headers now contains Authorization, x-amz-date, x-amz-security-token
const response = await fetch(`https://${url.hostname}${url.pathname}`, {
method: signed.method,
headers: signed.headers,
});
const data = await response.json();
Package @aws-crypto/sha256-js is part of the AWS SDK monorepo and comes in with @aws-sdk/signature-v4. If you need a lighter alternative, the aws4 npm package also signs VPC Lattice requests correctly when you specify service: "vpc-lattice-svcs".
Health check and target deregistration
VPC Lattice polls target health according to the target group's health check config. When scaling in Fargate tasks or terminating EC2 instances, deregister the targets first to avoid 503s:
import { DeregisterTargetsCommand } from "@aws-sdk/client-vpc-lattice";
// Called from your shutdown handler before the task stops
await lattice.send(new DeregisterTargetsCommand({
targetGroupIdentifier: tg.id,
targets: [{ id: "10.0.1.42", port: 3000 }],
}));
// Give in-flight requests time to drain before allowing the task to terminate
For ECS Fargate, wire this into the container's SIGTERM handler. VPC Lattice marks deregistered targets DRAINING and stops routing new requests within a few seconds.
Listing and inspecting services
import {
ListServicesCommand,
ListServiceNetworksCommand,
ListTargetGroupsCommand,
ListTargetsCommand,
} from "@aws-sdk/client-vpc-lattice";
// List all services in the account+region
for await (const page of paginateListServices({ client: lattice }, {})) {
for (const svc of page.items ?? []) {
console.log(svc.name, svc.status, svc.dnsEntry?.domainName);
}
}
// List all registered targets in a target group
const targetsResp = await lattice.send(new ListTargetsCommand({
targetGroupIdentifier: tg.id,
}));
for (const t of targetsResp.items ?? []) {
console.log(t.id, t.port, t.status, t.reasonCode);
// reasonCode on unhealthy: "HealthCheckFailed", "InitialHealthChecking", etc.
}
Pricing
VPC Lattice charges on three dimensions: service network association hours ($0.025/hour per VPC association, ~$18/mo), data processed ($0.025/GB in each direction), and requests ($0.0025 per 1,000 requests). For typical MCP server workloads with moderate API call volumes, the VPC association hours dominate. If you have one service network and four VPCs associated, expect ~$72/month in base charges before data transfer costs.