InternetGateway
Source:
src/AWS/EC2/InternetGateway.ts
An internet gateway provides a target for internet-routable traffic in a VPC, enabling bidirectional IPv4 and IPv6 connectivity between resources in your VPC and the public internet. A VPC can have at most one internet gateway attached at a time.
The only inputs are the optional vpcId to attach to and tags. Attaching a
gateway is not enough on its own to make a subnet public — you also need a
0.0.0.0/0 Route pointing at the gateway and a
RouteTableAssociation binding the subnet to that route table.
Creating an Internet Gateway
Section titled “Creating an Internet Gateway”Pass vpcId to create and attach the gateway in one step, or omit it to
create a standalone gateway and attach it later by setting the prop. Updating
vpcId moves the gateway between VPCs (detach then attach) without
recreating it.
Internet Gateway Attached to a VPC
const internetGateway = yield* AWS.EC2.InternetGateway("InternetGateway", { vpcId: myVpc.vpcId,});Creates the gateway and attaches it to the VPC immediately. The resulting
internetGatewayId (prefixed igw-) is what you reference from a route’s
gatewayId.
Detached Internet Gateway
const internetGateway = yield* AWS.EC2.InternetGateway("InternetGateway", {});Omitting vpcId creates an unattached gateway. This is occasionally useful
when the VPC is provisioned separately; add the vpcId prop later to attach
it.
Internet Gateway with Tags
const internetGateway = yield* AWS.EC2.InternetGateway("InternetGateway", { vpcId: myVpc.vpcId, tags: { Name: "production-igw" },});The tags map is merged with the alchemy auto-tags and can be changed in
place. A Name tag makes the gateway easy to identify in the AWS console.
Enabling Public Internet Access
Section titled “Enabling Public Internet Access”An internet gateway only carries traffic once a route table sends traffic to it and a subnet is associated with that table. The full pattern below makes a subnet public.
const internetGateway = yield* AWS.EC2.InternetGateway("InternetGateway", { vpcId: myVpc.vpcId,});
const publicRouteTable = yield* AWS.EC2.RouteTable("PublicRouteTable", { vpcId: myVpc.vpcId,});
const internetRoute = yield* AWS.EC2.Route("InternetRoute", { routeTableId: publicRouteTable.routeTableId, destinationCidrBlock: "0.0.0.0/0", gatewayId: internetGateway.internetGatewayId,});With the default route in place, any subnet associated with
publicRouteTable can send and receive internet traffic. Add an analogous
route with destinationIpv6CidrBlock: "::/0" to enable IPv6.