AWS PrivateLink — VPC Endpoint Services
Publish exactly one service to other VPCs and other accounts — and nothing else. No peering, no internet gateway, no NAT, no route table edits. The two VPCs never become one network and the provider's CIDRs are never exposed, so overlapping address space stops being a problem at all.
Mở ra đúng một service cho các VPC và account khác — ngoài nó ra không lộ thêm thứ gì. Không cần peering, không internet gateway, không NAT, không phải sửa route table. Hai VPC không bao giờ nhập lại thành một mạng, và CIDR của bên provider thì bên kia không hề nhìn thấy — nên chuyện trùng dải địa chỉ cũng hết là vấn đề.
The shape is always the same: provider puts the app behind a Network Load Balancer and publishes it as an endpoint service; consumer creates an interface endpoint, which is an ENI with a private IP in their own subnets. That is the entire mechanism — and it is exactly what an interface endpoint to an AWS service is, too.
Hình dạng lúc nào cũng vậy: phía provider đặt ứng dụng sau một Network Load Balancer rồi publish thành endpoint service; phía consumer tạo một interface endpoint, thực chất là một ENI có private IP nằm trong subnet của chính họ. Cơ chế chỉ có thế — và interface endpoint trỏ tới service của AWS cũng chính là thứ này, không khác gì.
PrivateLink is the answer when… / not the right tool when…Khi nào PrivateLink là đáp án… / khi nào không phải
Reach for PrivateLinkChọn PrivateLink
- You are the provider of a SaaS or an internal service and consumers live in other accounts you do not control. Thousands of them is fine — there is nothing to mesh.Bạn là bên cung cấp một SaaS hoặc một service nội bộ, còn người dùng nằm ở các account khác mà bạn không quản. Hàng nghìn consumer cũng không sao — chẳng phải đấu nối gì với nhau cả.
- A shared service in a hub account — auth, licensing, a logging API — consumed by dozens of workload VPCs.Một service dùng chung đặt ở account hub — xác thực, cấp license, API nhận log — và hàng chục VPC workload khác gọi vào.
- The consumer's CIDRs overlap yours, or you simply have no idea what they are. PrivateLink never routes to the provider's addresses, so it does not care.CIDR của consumer trùng với của bạn, hoặc đơn giản là bạn không biết họ dùng dải nào. PrivateLink không định tuyến tới địa chỉ của provider nên chuyện đó không liên quan.
- Audit says "they may reach that one port and nothing else" — with PrivateLink there is nothing else to reach, by construction.Bên audit yêu cầu "chỉ được chạm tới đúng cổng đó, ngoài ra không gì khác" — với PrivateLink thì bản thân thiết kế đã không có gì khác để chạm tới.
- On-premises over a private VIF needs private access to an AWS service: interface endpoints work from Direct Connect and VPN, a gateway endpoint does not.Từ on-prem đi qua private VIF mà cần truy cập private vào một service của AWS: interface endpoint dùng được từ Direct Connect và VPN, còn gateway endpoint thì không.
Not the right toolKhông phải chỗ dùng nó
- You need general network reachability — many hosts, many ports, both directions. That is VPC Peering, not a published service.Bạn cần hai mạng thông nhau thật sự — nhiều host, nhiều cổng, cả hai chiều. Việc đó là của VPC Peering, không phải của một service đem publish.
- Many VPCs must all reach each other. Meshing with PrivateLink means one endpoint service per service per direction — use Transit Gateway.Nhiều VPC phải liên lạc qua lại với nhau. Làm bằng PrivateLink thì mỗi service, mỗi chiều lại phải dựng một endpoint service — trường hợp này dùng Transit Gateway.
- You only need S3 or DynamoDB from inside the VPC, nothing from on-premises and nothing cross-Region → a gateway endpoint is free and needs no ENI. See VPC Endpoints.Chỉ cần gọi S3 hoặc DynamoDB từ trong VPC, không có nhu cầu từ on-prem cũng không cross-Region → gateway endpoint miễn phí và chẳng cần ENI nào. Xem VPC Endpoints.
- The service cannot sit behind an NLB. No Layer-4 entry point, no endpoint service — that is a hard requirement, not a preference.Service không thể đặt sau một NLB. Không có điểm vào tầng 4 thì không publish endpoint service được — đây là điều kiện bắt buộc, không phải khuyến nghị.
- You want the provider to call the consumer. PrivateLink only flows consumer → provider; a callback needs its own path, its own endpoint service, or a queue.Bạn muốn provider chủ động gọi ngược về consumer. PrivateLink chỉ chạy một chiều consumer → provider; muốn callback thì phải có đường riêng, một endpoint service riêng, hoặc đi qua queue.
The shape — an NLB on one side, an ENI on the otherHình dạng — một bên là NLB, bên kia là ENI
Provider: application → NLB → published as a VPC endpoint service. Consumer: consumer app → endpoint ENI → PrivateLink → NLB → service. Nothing else is created, nothing else is routed, and the consumer never learns a single address from the provider's VPC. Phía provider: ứng dụng → NLB → đem publish thành VPC endpoint service. Phía consumer: app → ENI của endpoint → PrivateLink → NLB → service. Không sinh thêm thứ gì, không thêm route nào, và consumer không hề biết một địa chỉ nào bên trong VPC của provider.
Read the shading: everything on the right is opaque to the consumer. The only thing that exists on the consumer's side is an ENI with a private IP in their own subnet, so the "network" the consumer sees ends at that ENI. Both VPCs are 10.0.0.0/16 on purpose — with peering that diagram would not be buildable at all.
Hãy để ý phần tô đậm: mọi thứ bên phải đều mờ tịt với consumer. Bên phía consumer chỉ tồn tại đúng một ENI mang private IP nằm trong subnet của họ, nên "mạng" mà họ nhìn thấy dừng lại ngay tại cái ENI đó. Hai VPC đều để 10.0.0.0/16 là cố ý — nếu dùng peering thì hình này không dựng nổi.
Who is allowed to connect — two controls, two ownersAi được phép kết nối — hai lớp kiểm soát, hai người quản
PrivateLink vs VPC Peering — the distinction to memorisePrivateLink và VPC Peering — chỗ khác nhau phải thuộc
Peering connects networks: routes on both sides, reach into each other's subnets, CIDRs must not overlap, and it is symmetric. PrivateLink publishes a service: the consumer sees one endpoint and nothing else of the provider's network, it is one-directional (consumer → provider), and overlapping CIDRs do not matter. Peering là nối hai mạng lại với nhau: hai bên đều phải thêm route, với tới subnet của nhau, CIDR không được trùng, và quan hệ là đối xứng. PrivateLink là đem một service ra publish: consumer chỉ thấy đúng một endpoint, ngoài ra không thấy gì trong mạng của provider, luồng chỉ đi một chiều (consumer → provider), và CIDR trùng nhau cũng không sao.
Same two VPCs, two completely different relationships. On the left the arrow points both ways and the boxes are open to each other; on the right the arrow points one way and stops at an endpoint. If a question mentions overlapping CIDRs, or "must not have network access to the rest of the VPC", the left-hand picture is already ruled out.
Vẫn hai VPC đó nhưng là hai kiểu quan hệ hoàn toàn khác nhau. Bên trái mũi tên đi hai chiều, hai cái hộp mở toang ra với nhau; bên phải mũi tên chỉ đi một chiều và dừng lại ở endpoint. Đề bài mà nhắc tới CIDR trùng nhau, hoặc "không được có quyền truy cập mạng vào phần còn lại của VPC", thì hình bên trái coi như đã bị loại.
An AWS-service interface endpoint is PrivateLinkInterface endpoint tới service của AWS chính là PrivateLink
Same machinery, different provider. When you create an interface endpoint for Secrets Manager, SSM or ECR, you are creating an ENI with a private IP and a security group in your subnet, and PrivateLink carries the traffic to a service fronted by a load balancer on the AWS side. AWS is simply the provider. Two things people memorise separately are one thing. Vẫn bộ máy đó, chỉ khác ai là provider. Khi bạn tạo interface endpoint cho Secrets Manager, SSM hay ECR, thứ bạn tạo ra là một ENI có private IP và security group trong subnet của mình, rồi PrivateLink đưa traffic tới một service nằm sau load balancer ở phía AWS. AWS đóng vai provider, chỉ vậy thôi. Hai khái niệm mà nhiều người học thuộc riêng rẽ thực ra là một.
EC2 → VPCE ENI → PrivateLink → AWS service · this is an interface endpoint for SSM, ECR, KMS, Secrets Manager…đây chính là interface endpoint cho SSM, ECR, KMS, Secrets Manager…
app → VPCE ENI → PrivateLink → NLB → service · identical picture; you supply the NLB that AWS supplies for its own serviceshình vẽ y hệt; chỉ khác là NLB do bạn dựng, còn service của AWS thì AWS tự lo
vpce-… name.Làm cho hostname bình thường phân giải ra private IP của endpoint ngay trong VPC, nên code client không phải sửa gì. Không bật thì phải gọi bằng tên vpce-….
PrivateLink for S3 with Direct ConnectPrivateLink cho S3 khi có Direct Connect
On-premises reaching S3 has two shapes. Over a public VIF the data centre talks to S3 directly on AWS public endpoints. Over a private VIF it lands in the VPC first, then goes out through PrivateLink and an interface endpoint to S3. Interface endpoints work from Direct Connect and VPN; a gateway endpoint does not — that is the whole reason to use one here. Từ on-prem đi tới S3 có hai kiểu. Đi qua public VIF thì data center nói chuyện thẳng với S3 qua các endpoint public của AWS. Đi qua private VIF thì traffic vào VPC trước, rồi từ đó ra S3 bằng PrivateLink và một interface endpoint. Interface endpoint dùng được từ Direct Connect và VPN, còn gateway endpoint thì không — đó chính là lý do duy nhất khiến ta chọn interface endpoint ở đây.
Same S3, same Direct Connect, two virtual interfaces. The public VIF reaches S3's public endpoint with nothing built in a VPC — private wiring, public destination. The private VIF is the one the exam wants when "must not touch a public endpoint" appears: it lands in the VPC, passes an interface endpoint's security group and endpoint policy, and rides PrivateLink to S3. The one path that does not exist here is a gateway endpoint — it is a route table entry, unreachable from outside the VPC.
Vẫn S3 đó, vẫn Direct Connect đó, chỉ khác ở hai virtual interface. Public VIF đi tới endpoint public của S3 mà không cần dựng gì trong VPC — đường đi private, đích đến public. Private VIF mới là thứ đề thi muốn khi xuất hiện câu "không được chạm endpoint public": traffic vào VPC, đi qua security group và endpoint policy của interface endpoint, rồi theo PrivateLink tới S3. Đường duy nhất không tồn tại ở đây là gateway endpoint — nó chỉ là một dòng route table, từ ngoài VPC không với tới được.
Cross-Region connectivityKết nối cross-Region
An interface endpoint does not have to point at something in its own Region. EC2 in us-east-1 → interface endpoint → S3 in eu-west-1 works, and so does an endpoint in us-east-1 reaching the NLB that fronts your own service in ap-east-1. One endpoint in the consumer's VPC, the service wherever it happens to live.
Interface endpoint không bắt buộc phải trỏ tới thứ nằm cùng Region với nó. EC2 ở us-east-1 → interface endpoint → S3 ở eu-west-1 là chạy được, và một endpoint ở us-east-1 gọi tới NLB đang đứng trước service của bạn ở ap-east-1 cũng vậy. Consumer chỉ cần một endpoint trong VPC của mình, còn service nằm ở Region nào cũng được.
Things that catch you outNhững chỗ dễ sập bẫy
- A gateway endpoint is not PrivateLink. It is a route table entry, it creates no ENI, it takes no security group, and it is unreachable from on-premises, from a peered VPC or from another Region. The moment the requirement leaves the VPC, the answer becomes an interface endpoint. Gateway endpoint không phải PrivateLink. Nó chỉ là một dòng trong route table, không sinh ENI, không gắn được security group, và từ on-prem, từ VPC đã peering hay từ Region khác đều không với tới được. Hễ yêu cầu vượt ra ngoài phạm vi VPC là đáp án chuyển sang interface endpoint.
- PrivateLink is one-directional. The consumer initiates, the provider answers on that connection — and that is all. If the design needs the provider to call back into the consumer, that is a second, separate path: its own endpoint service, or a queue, or an event bus. PrivateLink chỉ chạy một chiều. Consumer mở kết nối, provider trả lời trên chính kết nối đó — hết. Nếu thiết kế cần provider chủ động gọi ngược về consumer thì đó là một đường thứ hai hoàn toàn tách biệt: một endpoint service riêng, hoặc đi qua queue, hoặc qua event bus.
- Two security groups sit in the path, not one. The client's SG must allow outbound to the endpoint, and the endpoint ENI's SG must allow inbound from the client. A connection that times out with everything else configured is almost always the second one, because people forget the endpoint has an SG at all. Trên đường đi có tới hai security group chứ không phải một. SG của client phải cho phép đi ra tới endpoint, và SG của ENI endpoint phải cho phép đi vào từ client. Cấu hình đủ hết mà kết nối vẫn treo rồi timeout thì gần như luôn là do cái thứ hai — vì người ta hay quên rằng bản thân endpoint cũng có SG.
- Nobody can connect until the provider says so. An endpoint service starts with an empty allowed principals list, and by default new connections stay pending acceptance. "The consumer created the endpoint but it never became available" is this, not a networking fault. Chưa được provider gật đầu thì không ai kết nối được. Endpoint service khi mới tạo có danh sách allowed principals rỗng, và mặc định kết nối mới sẽ nằm chờ ở trạng thái pending acceptance. Tình huống "consumer tạo endpoint rồi mà mãi không lên available" là do cái này, chứ không phải lỗi mạng.
- Do not authorise consumers by source IP. Traffic arrives at the provider's targets through the NLB, so the client's real address is not what you get. Identify the caller properly — the endpoint ID carried by Proxy Protocol v2, mTLS, or an application-level credential. Đừng phân quyền consumer dựa trên IP nguồn. Traffic tới target của provider là đi qua NLB, nên địa chỉ thật của client không phải thứ bạn nhìn thấy. Hãy định danh người gọi một cách đàng hoàng — dùng endpoint ID mà Proxy Protocol v2 mang theo, dùng mTLS, hoặc một credential ở tầng ứng dụng.
Exam reflexesPhản xạ khi thi
| The question says…Đề nói… | AnswerĐáp án |
|---|---|
| "Expose one internal service to thousands of VPCs, including third-party accounts""Mở một service nội bộ cho hàng nghìn VPC, kể cả account của bên thứ ba" | PrivateLink: NLB + VPC endpoint service; each consumer creates an interface endpointPrivateLink: NLB + VPC endpoint service; mỗi consumer tự tạo interface endpoint |
| "The two VPCs have overlapping CIDRs""Hai VPC có CIDR trùng nhau" | PrivateLink — peering and Transit Gateway are both out; nothing is routed to the provider's CIDRPrivateLink — peering và Transit Gateway đều loại; có gói nào định tuyến sang CIDR của provider đâu |
| "The consumer must not reach anything else in our VPC""Consumer không được chạm tới bất cứ thứ gì khác trong VPC của mình" | PrivateLink. Peering would hand over route-level reach to the whole CIDRPrivateLink. Dùng peering là trao luôn quyền với tới cả dải CIDR |
| "Restrict which consumers may connect to the published service""Giới hạn consumer nào được kết nối tới service đã publish" | Security group on the endpoint ENI + allowed principals and acceptance on the endpoint serviceSecurity group gắn vào ENI của endpoint + allowed principals và bước duyệt ở endpoint service |
| "The private service access must be fault tolerant""Đường truy cập private tới service phải chịu được lỗi" | NLB in multiple AZs and endpoint ENIs in multiple AZs — both sides, or it is notNLB trải nhiều AZ và ENI của endpoint cũng trải nhiều AZ — thiếu một bên là chưa đạt |
| "On-premises over Direct Connect must reach S3 without the public internet""Từ on-prem qua Direct Connect phải tới được S3 mà không đi qua internet công cộng" | Private VIF → VPC → PrivateLink interface endpoint → S3. A gateway endpoint cannot be used from on-premisesPrivate VIF → VPC → interface endpoint qua PrivateLink → S3. Gateway endpoint không dùng được từ on-prem |
"An app in us-east-1 must privately reach a service in another Region""App ở us-east-1 cần truy cập private tới service ở Region khác" |
Cross-Region interface endpoint — it can target S3 or the NLB fronting your service in the other RegionInterface endpoint cross-Region — trỏ được sang S3 hoặc sang NLB đang đứng trước service của bạn ở Region kia |