Sub topic 10
Publishing an endpoint service from a Network Load Balancer
This chapter assumes you know how Network Load Balancers (NLBs), target groups, and listeners work, and that you have read the PrivateLink overview chapter. You will turn an existing NLB into an endpoint service. Along the way you will control which accounts can connect and see what the provider side does and does not control.
What an endpoint service is
An endpoint service is a PrivateLink configuration, owned by the provider account, that points at a load balancer in the provider's VPC. Consumers never see that VPC's network. They create an interface endpoint in their own VPC, and AWS carries traffic from the endpoint to your load balancer.
The load balancer must be a Network Load Balancer or a Gateway Load Balancer. This chapter covers the NLB case. The provider's work has four parts:
- Build the NLB and its targets.
- Create the endpoint service configuration.
- Decide who may request a connection.
- Accept or reject each connection request.
Step 1: Prepare the Network Load Balancer
The NLB is usually internal, because PrivateLink traffic does not need a public address. The following commands create an internal NLB, a target group, and a TCP listener. Replace the IDs and ARNs with your own.
aws elbv2 create-load-balancer \
--name my-svc \
--type network \
--scheme internal \
--subnets subnet-0aaa1111 subnet-0bbb2222
aws elbv2 create-target-group \
--name my-svc-tg \
--protocol TCP \
--port 443 \
--vpc-id vpc-0aaa1111bbb22222c \
--target-type instance
aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:111122223333:loadbalancer/net/my-svc/0123456789abcdef \
--protocol TCP \
--port 443 \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:111122223333:targetgroup/my-svc-tg/0123456789abcdefTwo properties of the NLB directly shape the endpoint service:
- Availability Zones. The service is offered only in the Availability Zones where the NLB has a subnet. A consumer can place endpoint network interfaces only in those zones. If your NLB covers two zones, consumers get two zones at most. Zone IDs, such as
use1-az1, are the stable identifiers. Zone names such asus-east-1amap to different physical zones in different accounts. - Cross-zone load balancing. With it off, each endpoint interface sends traffic to NLB targets in its own zone only. If a zone has no healthy targets, those connections fail. Turn cross-zone on if your targets are unevenly spread, and remember that it can add inter-zone data charges for you.
Step 2: Create the endpoint service configuration
This command publishes the NLB as a service with manual acceptance. It then allows one consumer account to request connections.
aws ec2 create-vpc-endpoint-service-configuration \
--network-load-balancer-arns arn:aws:elasticloadbalancing:us-east-1:111122223333:loadbalancer/net/my-svc/0123456789abcdef \
--acceptance-required
aws ec2 modify-vpc-endpoint-service-permissions \
--service-id vpce-svc-0123456789abcdef0 \
--add-allowed-principals arn:aws:iam::444455556666:rootThe output contains the service ID (vpce-svc-...) and the service name. The service name has the form com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0. You give this name to consumers, and they use it when they create their endpoint.
Step 3: Control who can connect
Two independent gates protect the service.
Allowed principals
The allowed principals list controls who may even request a connection. Entries can be an account root ARN, an IAM user, an IAM role, or * for everyone. An ARN ending in :root allows every identity in that account, provided that account's own IAM policies let them call ec2:CreateVpcEndpoint. A request from a principal that is not on the list is refused before it reaches you.
A new service starts with an empty list, so nobody can connect until you add a principal. Avoid * unless you intend a public service and have another control in place.
Acceptance
With --acceptance-required, every allowed request still waits in the pendingAcceptance state until you approve it. Without the flag, requests from allowed principals are accepted automatically. Acceptance is useful when you want a human or an automation step to confirm that the account ID is a known customer.
You manage requests with these commands:
aws ec2 describe-vpc-endpoint-connections \
--filters Name=service-id,Values=vpce-svc-0123456789abcdef0
aws ec2 accept-vpc-endpoint-connections \
--service-id vpce-svc-0123456789abcdef0 \
--vpc-endpoint-ids vpce-0123456789abcdef0
aws ec2 reject-vpc-endpoint-connections \
--service-id vpce-svc-0123456789abcdef0 \
--vpc-endpoint-ids vpce-0123456789abcdef0Rejecting a connection that was already accepted ends it. The consumer's endpoint moves to the rejected state and its traffic stops.
| Setting | Controls | If missing or wrong |
|---|---|---|
| Allowed principals | Who can request a connection | Consumer gets an authorization error when creating the endpoint |
| Acceptance required | Whether you approve each request | Requests from allowed principals connect automatically |
| NLB subnets | Which zones the service is offered in | Consumer cannot choose a subnet in a zone you do not cover |
| Target health | Whether traffic reaches an application | Endpoint is `available` but connections time out or reset |
What your targets see
Traffic that arrives through PrivateLink does not carry the consumer's real source address. Targets see the NLB's private IP addresses as the source, or addresses in the NLB's subnets, depending on configuration. This also means overlapping CIDR ranges are not a problem for PrivateLink, because the two networks never exchange routes.
If your application needs to know which consumer sent a request, enable proxy protocol v2 on the target group. The NLB then prepends a header that includes the ID of the consumer's endpoint (vpce-...). Your application must parse that header, and it must expect it on every connection. Turning the setting on for a target that does not parse it breaks the connection.
aws elbv2 modify-target-group-attributes \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:111122223333:targetgroup/my-svc-tg/0123456789abcdef \
--attributes Key=proxy_protocol_v2.enabled,Value=trueIf your NLB has security groups attached, check whether the NLB enforces its inbound rules on PrivateLink traffic. Depending on that setting, the rules apply to the endpoint traffic or are skipped. Make sure your rules match your intent before you publish.
Optional: a private DNS name for the service
Consumers can reach the service by the DNS names AWS generates for their endpoint. If you want them to use your own name, such as api.example.com, set a private DNS name on the service. AWS then requires you to prove you own the domain by publishing a TXT record. The DNS chapter covers the verification flow and how it affects consumers. The command to set the name is short:
aws ec2 modify-vpc-endpoint-service-configuration \
--service-id vpce-svc-0123456789abcdef0 \
--private-dns-name api.example.comCommon errors
- Consumer cannot find the service. The service name is wrong, or the consumer is in a different Region. Endpoint services are Regional, and cross-Region access needs an extra connectivity layer or specific cross-Region endpoint support.
- Consumer is refused at creation. The consumer's account or role is not in the allowed principals list.
- Endpoint stays in
pendingAcceptance. The provider has not accepted it yet. - Endpoint is
availablebut nothing responds. Check target health, the listener port, and the target group's security group. An NLB health check failure in one zone also affects traffic from that zone's endpoint interface when cross-zone is off. - Consumer cannot select a zone. The NLB has no subnet in that zone.
Exercise
A consumer account is on your allowed principals list and creates an interface endpoint to your service, which was created with --acceptance-required. The endpoint shows pendingAcceptance. Which command moves it to available, and which side runs it?
Show answer
The provider runs aws ec2 accept-vpc-endpoint-connections with the service ID and the consumer's endpoint ID (vpce-...). The consumer cannot accept its own request. Being on the allowed principals list only lets the consumer submit the request.
Exercise
Your NLB has subnets in us-east-1a and us-east-1b only. A consumer wants endpoint interfaces in us-east-1c. What happens, and how would you fix it?
Show answer
The consumer cannot place an interface in a zone where the service is not offered, so the request for us-east-1c fails. To fix it, add a subnet in that zone to the NLB (and register targets there if cross-zone load balancing is off). The service then becomes available in that zone.