Guide · AWS App Runner · VPC Connector · MCP Server
App Runner VPC Connector for MCP Servers — Accessing Private Databases and Services
By default, AWS App Runner services run in a managed network that cannot reach resources inside your VPC — including RDS databases, ElastiCache clusters, DocumentDB, MemoryDB, and any private EC2 instances or internal load balancers. A VPC connector bridges App Runner to your VPC, letting MCP tool handlers connect to private resources over their private IP addresses without exposing those resources to the public internet. This guide covers VPC connector creation, security group configuration, and accessing the most common private resources from MCP servers.
TL;DR
Create a VPC connector that specifies a list of subnet IDs (at least 2 AZs for resilience) and a security group for the App Runner outbound traffic. Attach it to your App Runner service. The database security group must allow inbound traffic on the DB port from the App Runner connector's security group. App Runner instances get a private IP in your VPC subnets when making outbound calls, so your database sees traffic coming from a known, controllable security group — not from an unpredictable internet IP. No NAT Gateway is required for VPC resources; a NAT Gateway is only needed if you also need internet access from within the VPC-connected App Runner service.
VPC connector architecture
When a VPC connector is attached to an App Runner service, the service gets an Elastic Network Interface (ENI) in each specified subnet. Outbound connections from the MCP server are routed through these ENIs. The key architecture points:
- The App Runner service is still publicly accessible (inbound HTTPS from the internet is unchanged)
- Only outbound traffic from the MCP server goes through the VPC connector
- The ENI gets a private IP from the subnet's CIDR range
- The ENI is associated with the security group(s) you specify in the connector
- Your private resources (RDS, ElastiCache) authorize traffic from the connector's security group
VPC connector subnets should be private subnets (no direct internet route). App Runner can still reach AWS service endpoints (DynamoDB, S3, Secrets Manager) via VPC endpoints or the AWS global network — but public internet calls from within VPC-connected App Runner require a NAT Gateway on the subnet route table.
Creating the VPC connector
# Step 1: Create a security group for the App Runner connector
# (This is the "source" SG — databases will authorize traffic FROM this SG)
aws ec2 create-security-group \
--group-name apprunner-mcp-connector-sg \
--description "App Runner MCP server VPC connector" \
--vpc-id vpc-0123456789abcdef0 \
--region us-east-1
# Note the GroupId, e.g.: sg-0abc123def456789a
# Step 2: Create the VPC connector
aws apprunner create-vpc-connector \
--vpc-connector-name mcp-server-vpc-connector \
--subnets subnet-0aaaa111bbbb222cc subnet-0dddd333eeee444ff \
--security-groups sg-0abc123def456789a \
--region us-east-1
# Note the VpcConnectorArn from the output
# Step 3: Attach the connector to your App Runner service
aws apprunner update-service \
--service-arn arn:aws:apprunner:us-east-1:ACCOUNT:service/my-mcp-server/SERVICE_ID \
--network-configuration '{
"EgressConfiguration": {
"EgressType": "VPC",
"VpcConnectorArn": "arn:aws:apprunner:us-east-1:ACCOUNT:vpcconnector/mcp-server-vpc-connector/1/HASH"
}
}' \
--region us-east-1
Subnet selection matters: use at least 2 subnets in different AZs so that if one AZ has an outage, App Runner can still route outbound traffic through the other. The connector ENIs are created in both subnets; App Runner chooses the healthiest one for each outbound connection.
Authorizing the connector to reach RDS
Once the connector is created, update the RDS security group to allow inbound traffic from the connector's security group on the database port:
# PostgreSQL (port 5432)
aws ec2 authorize-security-group-ingress \
--group-id sg-0rds111222333444a \
--protocol tcp \
--port 5432 \
--source-group sg-0abc123def456789a \
--region us-east-1
# MySQL/Aurora MySQL (port 3306)
aws ec2 authorize-security-group-ingress \
--group-id sg-0rds111222333444a \
--protocol tcp \
--port 3306 \
--source-group sg-0abc123def456789a \
--region us-east-1
In your MCP server's Node.js code, connect to RDS using the private endpoint hostname — not the public endpoint. When the VPC connector is attached, App Runner resolves the private DNS name within your VPC and connects directly:
// Use the private/internal endpoint (without .rds.amazonaws.com public suffix routing)
// This resolves within the VPC to a private IP
const pool = new Pool({
host: process.env.RDS_HOST, // e.g., my-db.cluster-xyz.us-east-1.rds.amazonaws.com
port: 5432,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
ssl: { rejectUnauthorized: true },
max: 5, // Keep pool small — each App Runner instance gets its own pool
});
Connecting to ElastiCache (Redis)
ElastiCache clusters have no public endpoint — they are only accessible from within the VPC. The VPC connector is required to reach ElastiCache from App Runner:
# Authorize App Runner connector SG to reach ElastiCache on port 6379
aws ec2 authorize-security-group-ingress \
--group-id sg-0elasticache555666 \
--protocol tcp \
--port 6379 \
--source-group sg-0abc123def456789a \
--region us-east-1
# For ElastiCache with TLS enabled (port 6380 by default for clusters with in-transit encryption)
aws ec2 authorize-security-group-ingress \
--group-id sg-0elasticache555666 \
--protocol tcp \
--port 6380 \
--source-group sg-0abc123def456789a \
--region us-east-1
// Connect using the ElastiCache cluster endpoint (private DNS, resolved within VPC)
import { createClient } from "redis";
const redisClient = createClient({
url: `rediss://${process.env.ELASTICACHE_HOST}:6380`, // TLS endpoint
socket: {
tls: true,
rejectUnauthorized: true,
},
});
await redisClient.connect();
// Reuse across tool handlers — do NOT reconnect per request
export { redisClient };
Accessing Secrets Manager and SSM Parameter Store with VPC connector
When a VPC connector with EgressType: "VPC" is attached, all outbound traffic from App Runner goes through the VPC — including calls to AWS service APIs. By default, Secrets Manager and SSM Parameter Store calls go to public endpoints, which are reachable only via internet. With VPC egress, you need VPC endpoints for these services, or the calls will fail:
# Create VPC interface endpoints for services your MCP tools call
# Secrets Manager
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0123456789abcdef0 \
--vpc-endpoint-type Interface \
--service-name com.amazonaws.us-east-1.secretsmanager \
--subnet-ids subnet-0aaaa111bbbb222cc subnet-0dddd333eeee444ff \
--security-group-ids sg-0vpc-endpoint-sg \
--private-dns-enabled
# SSM Parameter Store
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0123456789abcdef0 \
--vpc-endpoint-type Interface \
--service-name com.amazonaws.us-east-1.ssm \
--subnet-ids subnet-0aaaa111bbbb222cc subnet-0dddd333eeee444ff \
--security-group-ids sg-0vpc-endpoint-sg \
--private-dns-enabled
# DynamoDB (Gateway endpoint — free, no security group needed)
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0123456789abcdef0 \
--vpc-endpoint-type Gateway \
--service-name com.amazonaws.us-east-1.dynamodb \
--route-table-ids rtb-0private-route-table
Alternatively, set EgressType: "DEFAULT" (no VPC connector) and restrict your database to Secrets Manager via IAM database authentication instead of password auth — this avoids the VPC endpoint complexity for simpler setups.
VPC connector costs
VPC connectors themselves are free, but the ENIs created in your subnets do incur small data transfer charges:
- Intra-AZ traffic between the connector ENI and VPC resources: free
- Cross-AZ traffic (connector in AZ-A reaching a resource in AZ-B): $0.01/GB each direction
- VPC interface endpoints: ~$0.01/hr per AZ + $0.01/GB data processed
To minimize cross-AZ costs: deploy RDS, ElastiCache, and MemoryDB with multi-AZ, and ensure the subnets in your VPC connector span the same AZs as your database replicas. App Runner will prefer the same-AZ ENI when possible.
Troubleshooting connectivity
| Symptom | Likely cause | Fix |
|---|---|---|
| Connection timeout to RDS/ElastiCache | Security group ingress rule missing for connector SG | Add inbound rule from connector SG on correct port to the database SG |
| DNS resolution fails for database endpoint | Private DNS not enabled in VPC, or subnet DNS settings disabled | Enable enableDnsHostnames and enableDnsSupport on the VPC; check subnet ACLs allow UDP 53 |
| Secrets Manager / SSM calls fail with timeout after attaching VPC connector | VPC egress blocks public AWS endpoints; no VPC interface endpoint | Create VPC interface endpoints for secretsmanager and ssm in connector subnets |
| App Runner service deploys but tools fail with connection refused | RDS/ElastiCache in a different VPC or different region | Connector and databases must be in the same VPC and region; use VPC peering for cross-VPC scenarios |
| Intermittent connection errors under load | Connection pool exhausted across App Runner instances | Reduce pool max per instance; App Runner scales instances so total connections = max × instance count |
Related guides
- AWS App Runner for MCP servers: deployment, health checks, and IAM instance role
- App Runner auto scaling: concurrency, min/max instances, cold starts
- App Runner secrets management: Secrets Manager integration for MCP servers
- ElastiCache for MCP servers: Redis connection, session caching, pub/sub
- MCP server uptime monitoring