Sub topic 9
PrivateLink: exposing a service, not a network
This chapter assumes you know CIDR blocks, subnets, route tables, security groups, and what a Network Load Balancer (NLB) does. It introduces the PrivateLink model. The next two chapters build the provider and consumer sides with CLI commands.
The problem PrivateLink solves
Suppose a team in one AWS account runs an internal API. Fifty other VPCs, some in other accounts, need to call it. Two common answers are poor fits:
- Peering or Transit Gateway joins whole networks. Every consumer can then route to every address in the provider VPC, not just the API. The VPC CIDR ranges also must not overlap.
- Public exposure puts the API on the internet behind an internet gateway. Traffic leaves the private network, and you need extra controls to keep it safe.
AWS PrivateLink exposes one service to other VPCs. The consumer never gets a route into the provider's network. The consumer gets a private IP address inside its own VPC, and traffic sent to that address reaches the service.
The provider and consumer model
PrivateLink has two roles.
- Service provider. Owns the application. The provider puts it behind a load balancer and publishes an endpoint service. The provider decides who may connect.
- Service consumer. Creates an interface VPC endpoint in its own VPC. An interface endpoint is a set of elastic network interfaces (ENIs), one per chosen subnet. Each ENI gets a private IP from that subnet's range.
When a consumer client connects to an endpoint ENI, AWS carries the traffic over its internal network to the provider's load balancer. No internet gateway, NAT device, VPN, or peering connection is involved.
All three VPCs in the diagram use the same CIDR, 10.0.0.0/16. That works because no VPC has a route to another VPC's address space. Overlapping ranges are a real advantage of this model, and a later chapter returns to them.
What the provider controls
The provider side has three parts:
- A load balancer in front of the service. An endpoint service is backed by a Network Load Balancer, or by a Gateway Load Balancer for inspection appliances. This chapter focuses on the NLB case.
- The endpoint service configuration. It has a service name of the form
com.amazonaws.vpce.<region>.vpce-svc-.... Consumers use this name to create endpoints. - Access control. An allow list of IAM principals (account, user, or role ARNs) states who may request a connection. The provider can also require manual acceptance, so each connection request waits for approval.
The provider can list the services it offers, and consumers can look up the services visible to them:
aws ec2 describe-vpc-endpoint-services \
--service-names com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0The output includes the Availability Zones where the service is offered. The consumer must create endpoints in subnets that sit in those zones.
What the consumer controls
The consumer picks the VPC, the subnets, and the security groups for the endpoint. Each endpoint ENI has its own security group, so the consumer can restrict which clients may send traffic to it, for example only the application tier on one port. The consumer can also attach an endpoint policy to some endpoint types, which limits what actions go through the endpoint.
For an endpoint service you create yourself, you usually address it with the DNS names AWS generates for the endpoint. Those names resolve to the private IPs of the ENIs. The DNS chapter covers private DNS names.
PrivateLink compared with Transit Gateway
| Question | PrivateLink | Transit Gateway |
|---|---|---|
| What is shared? | One service on specific ports | Network reachability between attached networks |
| Direction of connections | Consumer to provider only | Any direction, if routes and security rules allow it |
| Overlapping CIDRs | Allowed | Not workable for routes to the overlapping ranges |
| Consumer's view | A private IP in its own subnet | Routes to the other VPC's real addresses |
| Main control point | Allow list, acceptance, security groups | Route tables, security groups, network ACLs |
| Typical use | SaaS, shared internal APIs, partner access | Hub-and-spoke networks, shared services, on-premises links |
PrivateLink is for access to an application. Transit Gateway is for connecting networks. If every VPC needs to reach many resources in every other VPC, use Transit Gateway. If many VPCs need to reach one service, PrivateLink limits what you expose.
Behaviors that surprise people
Traffic is one-directional. Only the consumer can start a connection. The provider cannot open a connection back to a consumer client through the endpoint. If the provider needs to call the consumer, you need a second endpoint service in the other direction, or a different connectivity pattern.
The provider does not see the client's real IP by default. Targets behind the NLB see the source address of the load balancer's private interface. To identify the consumer, enable Proxy Protocol v2 on the NLB target group. The header carries the endpoint ID, and the application must parse it. Because of this, source-IP allow lists in the provider application do not work as they would with a routed network.
Availability Zones must line up. An endpoint has an ENI in each subnet you choose. Traffic goes to the provider's load balancer nodes in the same zone when both sides have one. Zone IDs, not zone names, are the reliable way to match zones across accounts, because the name-to-zone mapping differs per account.
Endpoints come in several types. The one this tutorial focuses on is the interface endpoint. Others you will meet are the gateway endpoint (used for Amazon S3 and DynamoDB, which works through route table entries rather than ENIs) and the Gateway Load Balancer endpoint (used to send traffic to inspection appliances). Many AWS services, such as AWS Systems Manager and Amazon ECR, also offer interface endpoints, and these use the same PrivateLink mechanism.
Endpoints reach only what the NLB reaches. The consumer sees only the listener ports on the NLB. The consumer cannot probe other addresses in the provider VPC. This is the main security benefit.
Cost model
You pay for each interface endpoint per hour for every Availability Zone it uses, plus a per-gigabyte charge for data processed through it. The provider pays for the NLB. Check current prices for your Region. Cost grows with endpoints times zones, so a service consumed from 50 VPCs in 3 zones means 150 endpoint-zone hours billed. Plan this against the cost of a central hub.
Walk through one request
- A client in the consumer VPC resolves the service's DNS name to an endpoint ENI address, such as 10.0.1.25.
- The client opens a TCP connection to that address. The endpoint security group must allow it.
- AWS carries the connection to the provider's NLB over the AWS network.
- The NLB forwards it to a healthy target and returns the response over the same connection.
- If the allow list or acceptance state does not permit the connection, the endpoint stays in a pending or rejected state and no traffic flows.
When a connection fails, check the endpoint state first, then the endpoint security group, then NLB target health on the provider side.
Exercise
Two consumer VPCs both use 10.0.0.0/16, and the provider VPC also uses 10.0.0.0/16. Can both consumers use the provider's PrivateLink service? Name one reason it works and one limitation this design has.
Show answer
Yes. Each consumer reaches the service through an endpoint ENI with an address in its own subnet, and no route is created to the provider's address space, so the overlapping CIDRs do not conflict. One limitation is that connections are one-way, so the provider cannot start connections to consumer clients through the endpoint. Another is that the provider application sees the NLB's address as the source unless Proxy Protocol v2 is enabled.
Exercise
A team must give a partner's AWS account access to one internal HTTPS API, and nothing else in the VPC. Should they use VPC peering, Transit Gateway, or PrivateLink? Which two provider-side settings limit who can connect?
Show answer
PrivateLink, because it exposes one service rather than the network. The provider-side settings are the allow list of principals on the endpoint service and the requirement for manual acceptance of connection requests.