AWS Transit Gateway
One regional router that every VPC, VPN and Direct Connect Gateway plugs into. It turns a mesh of peerings into a star, and it is transitive — which is the one thing VPC Peering will never do for you.
Một router duy nhất trong Region, mọi VPC, VPN và Direct Connect Gateway đều cắm vào đó. Nó biến mớ peering chằng chịt thành hình sao, và quan trọng nhất là nó đi xuyên qua được — thứ mà VPC Peering không bao giờ làm được.
Two ideas carry the whole page: TGW route tables decide who may talk to whom, and TGW routes to attachments, never to a NAT Gateway ENI. Get those and everything else is detail.
Cả trang này xoay quanh hai ý: TGW route table quyết định ai được nói chuyện với ai, và TGW chỉ định tuyến tới attachment, không bao giờ trỏ thẳng vào ENI của NAT Gateway. Nắm hai ý đó rồi thì phần còn lại chỉ là chi tiết.
Reach for a Transit Gateway when… / peering is still fine when…Khi nào cần Transit Gateway… / khi nào peering vẫn ổn…
Transit GatewayDùng Transit Gateway
- You are past a handful of VPCs. Full mesh costs n(n−1)/2 peerings — 10 VPCs is 45 links, and every new VPC touches all the others.Số VPC đã vượt quá mức đếm trên đầu ngón tay. Nối full mesh tốn n(n−1)/2 peering — 10 VPC là 45 đường, và thêm một VPC mới là phải động vào tất cả những cái còn lại.
- Something needs transit: an App VPC using a NAT Gateway, NLB, PrivateLink or EFS that lives in another VPC.Có nhu cầu đi xuyên qua: App VPC muốn xài NAT Gateway, NLB, PrivateLink hay EFS nằm ở một VPC khác.
- On-premises is in the picture — one Direct Connect Gateway or VPN reaching many VPCs, instead of one link per VPC.Có on-premises trong sơ đồ — một Direct Connect Gateway hoặc VPN với tới được nhiều VPC, thay vì mỗi VPC phải kéo một đường riêng.
- A multi-account landing zone: the Network Services account owns the gateway and shares it with RAM.Mô hình landing zone nhiều account: account Network Services đứng tên gateway rồi chia sẻ ra bằng RAM.
- You need environment segmentation — Prod, Pre-Prod, Staging, Dev on one gateway with separate route tables.Cần tách môi trường — Prod, Pre-Prod, Staging, Dev chung một gateway nhưng route table riêng.
- The application needs IP Multicast. Nothing else in AWS does it.Ứng dụng cần IP Multicast. Trong AWS không còn lựa chọn nào khác.
Peering is still finePeering vẫn ổn
- Two VPCs, one talks to the other, end of story. A star with two points is just a line.Chỉ có hai VPC, một bên gọi sang bên kia, hết. Hình sao mà có hai đỉnh thì chỉ là một đoạn thẳng.
- No transit is needed — nobody is borrowing anyone's NAT, IGW or VPN.Không cần đi xuyên qua ai — không ai mượn NAT, IGW hay VPN của ai cả.
- Cost matters and the flow is chatty: TGW bills per attachment-hour plus per GB processed; peering has no hourly gateway charge and no processing fee on the hop.Chi phí quan trọng mà luồng dữ liệu lại rất nhiều: TGW tính tiền theo giờ cho mỗi attachment, cộng tiền theo GB đi qua; còn peering không có phí gateway theo giờ, cũng không tính phí xử lý ở chặng đó.
- You want the smallest blast radius: peering has no shared component in the middle to misconfigure or to lose.Bạn muốn phạm vi ảnh hưởng nhỏ nhất: peering không có thành phần dùng chung nào ở giữa để mà cấu hình sai hay chết cả cụm.
- You rely on referencing a security group across the link — that works over peering in the same Region, not across a TGW.Bạn đang tham chiếu security group qua đường nối — cái đó chỉ chạy với peering trong cùng Region, qua TGW thì không.
The mesh problem — why a hub exists at allVấn đề của mesh — vì sao phải có hub
Left unchecked, the topology grows into something nobody can hold in their head: VPN connections landing in one VPC, peerings between every pair, a Direct Connect Gateway hanging off the side. Transit Gateway replaces the mesh with hub-and-spoke — every network becomes one attachment on one gateway. Cứ để mặc thì sơ đồ mạng sẽ phình ra tới mức không ai nhớ nổi: VPN cắm vào một VPC nào đó, peering nối chéo mọi cặp, thêm một Direct Connect Gateway lủng lẳng bên rìa. Transit Gateway thay cả mớ đó bằng hub-and-spoke — mỗi mạng chỉ còn là một attachment trên một gateway duy nhất.
The count is the cheap argument; transitivity is the real one. Even if you were willing to draw 1,225 peerings, VPC B still could not use VPC A's NAT Gateway through them. The star does not just tidy the picture — it changes what is possible.
Con số 1.225 chỉ là lý do dễ thấy nhất; lý do thật nằm ở tính bắc cầu. Cho dù bạn đủ kiên nhẫn vẽ hết 1.225 đường peering, VPC B vẫn không thể đi nhờ NAT Gateway của VPC A. Hình sao không chỉ làm sơ đồ gọn hơn — nó mở ra những thứ trước đó không làm được.
The two routing layers — read this one twiceHai tầng định tuyến — đọc kỹ phần này
This is the mechanic that makes every TGW problem legible. The TGW route table only ever points at an attachment. It cannot point at a NAT Gateway, an instance or an ENI, because from the gateway's point of view a whole VPC is just one door. Once the packet is through that door, the VPC route table takes over and does the last hop. Đây là cơ chế làm cho mọi ca lỗi TGW trở nên dễ hiểu. TGW route table chỉ trỏ được vào attachment, không gì khác. Nó không trỏ được vào NAT Gateway, vào instance hay vào một ENI cụ thể, vì đứng từ phía gateway thì cả một VPC chỉ là một cánh cửa. Gói tin qua được cửa đó rồi thì VPC route table mới là bên tiếp quản và lo chặng cuối.
Six bands, two owners. Blue bands are yours to fix in the VPC console; the purple band is the gateway's. Note that you never write the second band: a VPC has at most one attachment to a given gateway, so naming tgw-0a1b2c3d already names that door. It is drawn because it does two things — it carries the ENI the packet actually leaves through, and the attachment a packet arrives on is what decides which TGW route table is consulted. Most "TGW is broken" tickets are a missing route in a blue band, and the second most common is an attachment whose subnets do not cover the AZ the traffic is trying to reach.
Sáu ô, hai chủ sở hữu. Mấy ô màu xanh là phần bạn sửa trong console VPC; ô màu tím mới là phần của gateway. Để ý là ô thứ hai bạn không hề khai ở đâu cả: một VPC chỉ gắn được tối đa một attachment vào một gateway, nên viết tgw-0a1b2c3d là đã chỉ đúng cái cửa đó rồi. Nó vẫn được vẽ ra vì nó làm hai việc — nó giữ cái ENI mà gói tin thực sự đi ra, và attachment mà gói tin đi vào chính là thứ quyết định TGW sẽ tra ở route table nào. Phần lớn ca "TGW hỏng rồi" thật ra chỉ là thiếu một route ở ô xanh, và ca phổ biến thứ hai là attachment không có subnet ở đúng AZ mà traffic muốn tới.
blackhole, full stop. The NAT Gateway is reached by the Egress VPC's own route table, one layer down, after the packet has already arrived through the attachment ENI.
Không. Có muốn cũng chẳng tìm thấy target đó trong danh sách. Target của TGW route table chỉ gồm attachment và blackhole, hết. NAT Gateway là do route table của chính Egress VPC trỏ tới, ở tầng dưới, sau khi gói tin đã đi qua ENI của attachment vào bên trong VPC rồi.
Route tables are the segmentation leverRoute table chính là cần gạt phân vùng
Everything attaches to one gateway. Who can reach whom is decided entirely by which TGW route table an attachment is associated with, and what that table contains. You do not build a second gateway to isolate an environment — you build a second route table. Tất cả cùng cắm vào một gateway. Ai nói chuyện được với ai hoàn toàn phụ thuộc vào attachment được gán vào TGW route table nào, và trong bảng đó có những route gì. Muốn cô lập một môi trường thì không dựng thêm gateway — chỉ tạo thêm một route table.
Worked example — four environments, one gatewayVí dụ cụ thể — bốn môi trường, một gateway
A Network Services account owns the Transit Gateway. Prod, Pre-Prod, Staging and Dev each live in their own account with their own VPC, and each creates an attachment onto the shared gateway. Then the gateway is split in two by route table. Transit Gateway do account Network Services đứng tên. Prod, Pre-Prod, Staging và Dev mỗi môi trường một account, một VPC riêng, và mỗi bên tạo một attachment lên gateway dùng chung. Sau đó gateway được chẻ làm đôi bằng route table.
| Prod Route Table | Staging Route Table | |
|---|---|---|
| Associated attachmentsAttachment được gán vào | Prod (VPC-A, 10.1.0.0/16) and Pre-Prod (VPC-B, 10.2.0.0/16)Prod (VPC-A, 10.1.0.0/16) và Pre-Prod (VPC-B, 10.2.0.0/16) |
Staging (VPC-C, 10.3.0.0/16) and Dev (VPC-D, 10.4.0.0/16)Staging (VPC-C, 10.3.0.0/16) và Dev (VPC-D, 10.4.0.0/16) |
| Routes it containsRoute bên trong | 10.1.0.0/16 → Attachment-A10.2.0.0/16 → Attachment-B |
10.3.0.0/16 → Attachment-C10.4.0.0/16 → Attachment-D |
| Who they can reachVới tới được ai | each other, and nothing else on the gatewaychỉ hai bên với nhau, ngoài ra không ai khác trên gateway | each other, and nothing else on the gatewaychỉ hai bên với nhau, ngoài ra không ai khác trên gateway |
| Why Prod cannot see DevVì sao Prod không thấy Dev | A packet from Prod for 10.4.x.x is looked up in the Prod table, which has no entry for it. No route, no delivery. Both VPCs are attached to the same gateway and it makes no difference at all.Gói tin từ Prod đi tới 10.4.x.x sẽ được tra trong bảng Prod, mà bảng đó không có dòng nào cho dải này. Không có route thì không đi được. Hai VPC vẫn cắm chung một gateway, nhưng điều đó chẳng thay đổi gì cả. |
|
Central NAT Gateway — the flagship patternNAT Gateway tập trung — pattern tiêu biểu nhất
Twenty App VPCs, twenty pairs of NAT Gateways, twenty Elastic IPs for the partner to allowlist. Instead: one Egress VPC holds the NAT Gateways — still one per AZ, that rule never goes away — and the IGW. Every App VPC routes 0.0.0.0/0 to its TGW attachment and gets the internet through the shared exit.
Hai mươi App VPC là hai mươi cặp NAT Gateway, hai mươi Elastic IP để đối tác allowlist. Thay vào đó: một Egress VPC giữ toàn bộ NAT Gateway — vẫn mỗi AZ một cái, quy tắc đó không bao giờ mất — cùng với IGW. Mọi App VPC chỉ cần trỏ 0.0.0.0/0 vào attachment của mình là ra được internet qua lối chung đó.
Read the App route table as a policy statement: "the internet, yes; anything private, no." The three blackhole lines are what keep App1 and App2 apart, and they beat the default route because the most specific match wins. The Egress table only needs the return paths.
Hãy đọc bảng route của App như một câu chính sách: "ra internet thì được; còn đi vào dải private thì không". Ba dòng blackhole chính là thứ giữ App1 và App2 tách nhau, và chúng thắng route mặc định vì route nào hẹp hơn thì thắng. Bảng Egress chỉ cần đủ đường cho traffic đi ngược về.
0.0.0.0/0 to an attachment.
Chỉ phải trả tiền cho một bộ NAT Gateway thay vì mỗi VPC một bộ. Chỉ có một cặp Elastic IP để đưa cho đối tác allowlist, và không đổi về sau. Chỉ một chỗ duy nhất để sau này gắn thêm lớp kiểm tra traffic đi ra. Và các App VPC không cần subnet public, cũng chẳng cần IGW — route duy nhất hướng ra ngoài của chúng là 0.0.0.0/0 trỏ vào một attachment.
Sharing, peering, and the on-premises sideChia sẻ, peering, và phía on-premises
Share it with AWS RAM — share, accept, useChia sẻ bằng AWS RAM — share, accept, use
The gateway lives in one account; the VPCs that need it live everywhere else. AWS RAM shares the Transit Gateway for VPC attachments across accounts or across an entire AWS Organization. The flow is three steps: account A shares, account B accepts, account B uses it — B creates its own attachment onto A's gateway, from its own account. Gateway nằm ở một account, còn các VPC cần dùng nó thì nằm rải khắp nơi. AWS RAM chia sẻ Transit Gateway để các bên tạo VPC attachment, sang từng account hoặc cho cả AWS Organization. Luồng có ba bước: account A share, account B accept, rồi B use — tức là B tự tạo attachment của mình lên gateway của A, ngay trong account của B.
Peering Transit Gateways — inter- and intra-RegionPeering giữa các Transit Gateway — cùng Region và khác Region
- You can peer Transit Gateways to each other — across Regions, or between two gateways in the same Region (yours, or a third party's). That is how a hub TGW ties several regional gateways together. Bạn có thể peer các Transit Gateway với nhau — khác Region, hoặc hai gateway trong cùng một Region (của bạn, hoặc của một bên thứ ba). Đây là cách một TGW đóng vai hub gom nhiều gateway ở các Region lại.
- Billing: hourly for each peering attachment, with no data processing charge. If the data actually crosses Regions through the attachment, standard data transfer applies on top. Về tiền: tính theo giờ cho mỗi peering attachment, và không thu phí xử lý dữ liệu. Nhưng nếu dữ liệu thật sự đi xuyên Region qua attachment đó thì vẫn phải trả phí data transfer thông thường.
- To set it up you specify the Transit Gateway ID of the far side. Note that a peering attachment does not propagate routes — add static routes pointing at it. Khi tạo, bạn khai Transit Gateway ID của đầu bên kia. Lưu ý: peering attachment không tự propagate route — phải tự thêm static route trỏ vào nó.
Direct Connect, in one paragraphDirect Connect, gói trong một đoạn
Direct Connect is not a VPC-to-VPC mechanism. It is a private, dedicated physical link from your data centre to AWS — no internet in the path. On its own it connects on-premises to AWS; combined with a Direct Connect Gateway in front of a Transit Gateway, that one on-prem connection reaches many VPCs, across Regions. Pair it with TGW peering and a single office link serves gateways in us-east-1 and us-west-2 alike. It gets its own page later.
Direct Connect không phải là cách nối VPC với VPC. Nó là một đường truyền vật lý riêng, dành riêng, kéo từ data center của bạn tới AWS — không đi qua internet. Bản thân nó chỉ nối on-premises với AWS; nhưng đặt thêm một Direct Connect Gateway phía trước Transit Gateway thì chỉ một đường on-prem đó với tới được rất nhiều VPC, ở nhiều Region. Kết hợp thêm TGW peering nữa thì một đường duy nhất từ văn phòng phục vụ được cả gateway ở us-east-1 lẫn us-west-2. Phần chi tiết sẽ có trang riêng.
IP Multicast — the thing only this service doesIP Multicast — thứ duy nhất chỉ service này làm được
Three ways to address traffic: unicast = one to one, broadcast = one to everyone on the network, multicast = one sender to a chosen group of receivers. The sender transmits once; the network copies the packet to whoever has joined the group. Market data feeds, video distribution and old trading or telemetry software are built on it. Có ba kiểu gửi traffic: unicast = một tới một, broadcast = một tới tất cả mọi máy trong mạng, multicast = một người gửi tới một nhóm người nhận đã đăng ký. Bên gửi chỉ phát một lần; phần nhân bản gói tin cho từng thành viên trong nhóm là việc của mạng. Các hệ thống bắn giá chứng khoán, phân phối video, hay phần mềm giao dịch và telemetry đời cũ đều xây trên cơ chế này.
- A VPC does not behave like a traditional LAN — there is no broadcast domain and no multicast by default. Software that "just worked" in the data centre will find nobody listening. Một VPC không hoạt động giống một LAN truyền thống — mặc định không có broadcast domain, cũng không có multicast. Phần mềm ở data center "cắm là chạy" đem lên đây sẽ thấy không ai nghe cả.
- Transit Gateway Multicast is the exception, and the only one in AWS. If a question mentions multicast at all, this is the answer — there is nothing to compare it against. Transit Gateway Multicast là ngoại lệ duy nhất trong toàn bộ AWS. Đề bài nhắc tới multicast là gần như chắc chắn đáp án nằm ở đây — không có phương án nào khác để mà so.
- The shape is a multicast domain on the gateway: you register the subnets that take part, and sources and group members are the ENIs inside them. Cách tổ chức là một multicast domain trên gateway: bạn đăng ký những subnet tham gia, còn nguồn phát và thành viên nhóm chính là các ENI nằm trong những subnet đó.
Things that catch you outNhững chỗ hay sập bẫy
- Attaching a VPC changes nothing in your subnets. The attachment is only the door; the VPC route tables still need an entry sending the remote CIDR to the attachment. This is the single most common "it doesn't work". Cắm VPC vào gateway không tự động thay đổi gì trong subnet của bạn. Attachment chỉ là cái cửa; route table của VPC vẫn phải có dòng trỏ dải CIDR bên kia vào attachment. Đây là nguyên nhân số một của các ca "không chạy".
- Subnet choice on the attachment is load-bearing. The attachment can only deliver into AZs where you gave it a subnet. Instances in an AZ you skipped are unreachable through the gateway, even though the route looks perfect. Pick one subnet per AZ you use. Chọn subnet cho attachment không phải chuyện hình thức. Attachment chỉ giao được traffic vào những AZ mà bạn đã cấp subnet cho nó. Instance nằm ở AZ bạn bỏ sót sẽ không ai tới được qua gateway, dù route nhìn vào thấy đúng hoàn toàn. Nhớ chọn mỗi AZ đang dùng một subnet.
-
Overlapping CIDRs still break everything. A Transit Gateway routes, it does not translate. Two VPCs both on
10.0.0.0/16cannot coexist behind it any more than they could over peering. CIDR trùng nhau vẫn làm hỏng hết. Transit Gateway chỉ định tuyến chứ không dịch địa chỉ. Hai VPC cùng dùng10.0.0.0/16thì đứng sau TGW cũng bế tắc y như khi đi qua peering. - Security group referencing does not cross the gateway. Over peering in the same Region you can allow "the SG of that app"; across a TGW you are back to writing CIDRs. Tham chiếu security group không đi qua được gateway. Với peering trong cùng Region bạn có thể mở luật cho "cái SG của app kia"; còn qua TGW thì đành quay lại viết CIDR.
- Blackhole is a feature, not damage. "Attached but must not talk" is expressed as a blackhole route, and it wins over a broader route because the most specific match applies. That is the trick behind the centralised-egress table. Blackhole là tính năng, không phải sự cố. Cái ý "vẫn cắm vào nhưng cấm nói chuyện" được diễn đạt bằng một route blackhole, và nó thắng route rộng hơn vì route nào hẹp hơn thì thắng. Đó chính là mẹo đứng sau bảng route của pattern egress tập trung.
- Cross-AZ flow stickiness. A flow stays on the AZ it entered through unless you enable appliance mode on the attachment. Put a stateful firewall or NAT appliance behind a TGW without it and return traffic can come back through a different AZ and get dropped. Traffic bị "dính" vào AZ mà nó đi vào. Một flow sẽ ở nguyên AZ mà nó vào, trừ khi bạn bật appliance mode trên attachment. Đặt firewall stateful hay NAT appliance sau TGW mà quên bật thì traffic chiều về có thể đi vòng qua AZ khác và bị chặn.
Exam reflexesPhản xạ khi thi
| The scenario says…Đề bài nói… | Reach forChọn ngay |
|---|---|
| "Dozens of VPCs plus on-premises, the peering mesh is unmanageable""Mấy chục VPC cộng thêm on-premises, mớ peering không quản nổi nữa" | Transit Gateway, hub-and-spoke. Transitive, and the link count goes from n(n−1)/2 to n.Transit Gateway, mô hình hub-and-spoke. Bắc cầu được, và số đường nối tụt từ n(n−1)/2 xuống còn n. |
| "Prod must never reach Dev, but both attach to the same gateway""Prod tuyệt đối không được với tới Dev, mà cả hai cùng cắm vào một gateway" | Two TGW route tables. Associate Prod and Pre-Prod with one, Staging and Dev with the other. Never a second gateway.Hai TGW route table. Association Prod và Pre-Prod vào bảng này, Staging và Dev vào bảng kia. Đừng bao giờ dựng thêm gateway thứ hai. |
| "A single internet exit point for every VPC, one IP to allowlist""Chỉ một lối ra internet cho mọi VPC, chỉ một IP để đối tác allowlist" | Central NAT Gateway in an Egress VPC (one NAT per AZ), App VPCs route 0.0.0.0/0 to the TGW attachment.NAT Gateway tập trung trong một Egress VPC (mỗi AZ một NAT), các App VPC trỏ 0.0.0.0/0 vào TGW attachment. |
| "The TGW route table points at the NAT Gateway and traffic dies""TGW route table trỏ vào NAT Gateway mà traffic vẫn chết" | It cannot. TGW routes to attachments only — the Egress VPC route table is what sends the packet on to the NAT.Không trỏ được. TGW chỉ định tuyến tới attachment — chính route table của Egress VPC mới là bên đẩy gói tin tới NAT. |
| "VPC B must use VPC A's NAT Gateway / NLB / PrivateLink / EFS""VPC B phải dùng NAT Gateway / NLB / PrivateLink / EFS của VPC A" | Not peering — it has no transit. Attach both to a Transit Gateway.Không phải peering — peering không bắc cầu được. Cắm cả hai vào một Transit Gateway. |
| "One on-prem link must privately reach VPCs in several Regions""Một đường on-prem duy nhất phải với tới VPC ở nhiều Region theo đường private" | Direct Connect + Direct Connect Gateway → Transit Gateway, and TGW peering between the Regions.Direct Connect + Direct Connect Gateway → Transit Gateway, rồi peering TGW giữa các Region với nhau. |
| "The gateway lives in a Network Services account, the VPCs elsewhere""Gateway nằm ở account Network Services, còn VPC thì ở các account khác" | AWS RAM: share the TGW across accounts or the whole Organization — share → accept → use.AWS RAM: chia sẻ TGW sang các account hoặc cho cả Organization — share → accept → use. |
| "A legacy application needs IP multicast in AWS""Một ứng dụng cũ cần IP multicast trên AWS" | Transit Gateway Multicast. No other AWS service supports it, so there is no second candidate.Transit Gateway Multicast. Không service AWS nào khác hỗ trợ, nên cũng chẳng có phương án thứ hai để cân nhắc. |