RouteTableAssociation
Source:
src/AWS/EC2/RouteTableAssociation.ts
Associates a RouteTable with a subnet (or a gateway), making that
route table govern traffic for the associated resource. A subnet can be
associated with exactly one route table at a time; multiple subnets may share
the same route table.
Provide exactly one of subnetId or gatewayId. Changing the subnet or
gateway replaces the association, whereas pointing an existing association at
a different route table is applied in place via
ReplaceRouteTableAssociation.
Associating Subnets
Section titled “Associating Subnets”Associating a subnet overrides the VPC’s main route table for that subnet. This is how you make a subnet “public” (associate it with a table that has an internet-gateway route) or “private” (associate it with a NAT-gateway table).
Associate a Subnet with a Route Table
const association = yield* AWS.EC2.RouteTableAssociation("PublicSubnetAssociation", { routeTableId: publicRouteTable.routeTableId, subnetId: publicSubnet.subnetId,});Binds a single subnet to the route table so its instances follow that
table’s routes. The returned associationId (prefixed rtbassoc-) can be
used to track or replace the association.
Share One Route Table Across Multiple Subnets
const subnet1Association = yield* AWS.EC2.RouteTableAssociation("PublicSubnet1Association", { routeTableId: publicRouteTable.routeTableId, subnetId: publicSubnet1.subnetId,});
const subnet2Association = yield* AWS.EC2.RouteTableAssociation("PublicSubnet2Association", { routeTableId: publicRouteTable.routeTableId, subnetId: publicSubnet2.subnetId,});Declaring multiple associations against the same routeTableId gives every
listed subnet identical routing — a concise way to apply one public (or
private) routing policy across all subnets in a tier.
Associating Gateways (Edge Routing)
Section titled “Associating Gateways (Edge Routing)”Instead of a subnet, an association can target an internet gateway or
virtual private gateway via gatewayId. This “gateway route table
association” enables edge routing, where inbound traffic is inspected or
redirected (e.g. to a firewall appliance) as it enters the VPC.
const edgeAssociation = yield* AWS.EC2.RouteTableAssociation("EdgeAssociation", { routeTableId: ingressRouteTable.routeTableId, gatewayId: internetGateway.internetGatewayId,});Attaches the route table at the gateway rather than at a subnet, so traffic arriving from the internet is steered by this table — typically toward an inspection appliance before reaching its destination subnet.