Sub topic 11
Creating an interface endpoint in a consumer VPC
This chapter assumes you know CIDR blocks, subnets, route tables, security groups, and the AWS CLI. It also assumes you have read the previous chapter, where a provider published a Network Load Balancer (NLB) as an endpoint service. Here you work in the consumer account and connect to that service.
What an interface endpoint is
An interface endpoint is a set of elastic network interfaces (ENIs) that AWS creates in your subnets. Each ENI gets a private IP address from the subnet's CIDR range. Traffic sent to those addresses travels over the AWS network to the provider's service. It never crosses an internet gateway, NAT gateway, or VPN.
The consumer VPC and the provider VPC are not joined. The consumer can reach only the service behind the endpoint. The consumer cannot see other resources in the provider's VPC, and the provider cannot see the consumer's network. Because of this, the two VPCs may use overlapping CIDR ranges.
Traffic is one-way. The consumer opens connections to the service. The provider's targets see the connection coming from the NLB's private addresses, not from the consumer's addresses. If the provider needs to know the client, it must use Proxy Protocol v2 on the NLB.
What you need before you start
- The service name from the provider, in the form
com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0. - Permission for your account. The provider must have added your account (or role) to the service's allowed principals.
- A VPC with subnets in the Availability Zones (AZs) you want to use.
- A security group for the endpoint ENIs.
The consumer and provider must have the service available in the AZs you choose. An endpoint can only be placed in subnets whose AZs the service supports. Compare the service's AZs with yours first.
aws ec2 describe-vpc-endpoint-services \
--service-names com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0 \
--query "ServiceDetails[0].{AZs:AvailabilityZones,AcceptanceRequired:AcceptanceRequired,PrivateDns:PrivateDnsNames}"AZ names such as us-east-1a map to different physical zones in different accounts. If you and the provider use zone names, they may not line up. Use AZ IDs such as use1-az1 to compare, which are the same in every account.
Create the endpoint
You specify the endpoint type, the VPC, the service name, one subnet per AZ, and a security group.
aws ec2 create-vpc-endpoint \
--vpc-endpoint-type Interface \
--vpc-id vpc-0aaa1111bbb22222c \
--service-name com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0 \
--subnet-ids subnet-0aaa1111 subnet-0bbb2222 \
--security-group-ids sg-0123456789abcdef0The command returns an endpoint ID such as vpce-0123456789abcdef0. The endpoint starts in the pendingAcceptance state if the provider set --acceptance-required. The provider then accepts the request:
aws ec2 accept-vpc-endpoint-connections \
--service-id vpce-svc-0123456789abcdef0 \
--vpc-endpoint-ids vpce-0123456789abcdef0Run this in the provider account, not yours. The endpoint then moves through pending to available.
aws ec2 describe-vpc-endpoints \
--vpc-endpoint-ids vpce-0123456789abcdef0 \
--query "VpcEndpoints[0].{State:State,DnsNames:DnsEntries[].DnsName}"How to choose subnets
Each subnet you list gets one ENI. You can place only one subnet per AZ in a single endpoint.
- Use at least two AZs for production. If one AZ fails, clients in the other AZ still reach the service.
- Place the endpoint in the AZs where your clients run. Traffic that crosses AZs adds data transfer charges and latency.
- Use dedicated subnets if you want tight control over who can reach the ENIs with network ACLs.
You can add or remove subnets later with modify-vpc-endpoint:
aws ec2 modify-vpc-endpoint \
--vpc-endpoint-id vpce-0123456789abcdef0 \
--add-subnet-ids subnet-0ccc3333Security groups on the endpoint
The security group on the endpoint ENIs controls which clients in your VPC can send traffic to the service. It must allow inbound traffic on the port the service's NLB listener uses. The simplest rule references the client security group instead of a CIDR range.
aws ec2 authorize-security-group-ingress \
--group-id sg-0123456789abcdef0 \
--protocol tcp \
--port 443 \
--source-group sg-0fedcba9876543210Outbound rules on the client matter too. A client security group that denies egress on that port blocks the call before it reaches the endpoint. Network ACLs on the endpoint subnet apply as well.
No route table entry is needed
The endpoint adds no route to your subnet route tables. The ENIs have private addresses inside your VPC CIDR, so the existing local route already reaches them. This is a common point of confusion. In the previous chapters you added routes to a transit gateway. Here you add none.
The same holds for peered or transit-gateway-connected networks. A client in another VPC or on premises can reach the endpoint ENIs if routing to the endpoint's VPC exists and the security group allows it. This is one way the two services combine, covered in a later chapter.
Using the endpoint from a client
AWS creates DNS names for the endpoint. You can see them in the DnsEntries field. There are two kinds:
- A regional name such as
vpce-0123456789abcdef0-abcd1234.vpce-svc-0123456789abcdef0.us-east-1.vpce.amazonaws.com. It resolves to the ENI addresses in all the endpoint's AZs. - A zonal name, which has the AZ name added to the front. It resolves to the ENI in that one AZ.
Test from an instance in the consumer VPC:
nslookup vpce-0123456789abcdef0-abcd1234.vpce-svc-0123456789abcdef0.us-east-1.vpce.amazonaws.com
curl -v https://vpce-0123456789abcdef0-abcd1234.vpce-svc-0123456789abcdef0.us-east-1.vpce.amazonaws.com/healthIf the provider configured a private DNS name for the service and you enable private DNS on the endpoint, you can use that friendly name instead. The next chapter covers that setting and how it interacts with access control.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `create-vpc-endpoint` fails with an invalid service error | Your account is not in the allowed principals, or the service name is wrong | Ask the provider to add your principal, and check the name |
| Error that the subnet's AZ is not supported | The service is not offered in that AZ | Compare AZ IDs with `describe-vpc-endpoint-services` |
| Endpoint stays in `pendingAcceptance` | The provider has not accepted | Ask the provider to run `accept-vpc-endpoint-connections` |
| Connection times out | Endpoint security group, client egress rule, or network ACL blocks the port | Allow the service port on both sides |
| Connection works from one AZ only | Targets in the provider's NLB are unhealthy in the other AZ, or cross-zone load balancing is off | Check the NLB target health with the provider |
| Name does not resolve from another VPC | The endpoint DNS names are not visible there | Add Route 53 Resolver rules or a shared private hosted zone |
Cleaning up
Deleting the endpoint removes its ENIs. The provider's service is unaffected.
aws ec2 delete-vpc-endpoints \
--vpc-endpoint-ids vpce-0123456789abcdef0Exercise
You created an interface endpoint in subnets in two AZs. A teammate asks which route table entries to add so clients can reach the service. What do you tell them, and what two things should they check if connections time out?
Show answer
No route entries are needed, because the endpoint ENIs have private IPs inside the VPC CIDR and the local route already covers them. If connections time out, check that the endpoint's security group allows inbound traffic on the service port from the client, and that the client's security group and the subnet network ACLs allow the traffic out and back.
Exercise
The provider requires acceptance. You run create-vpc-endpoint and then describe-vpc-endpoints. The state is pendingAcceptance. Which account must take the next action, and with which command?
Show answer
The provider account must act. It runs aws ec2 accept-vpc-endpoint-connections with the service ID and the endpoint ID. After that, the endpoint moves to pending and then available.