Skip to content
GitHubXDiscord

InternetGateway

The InternetGateway resource allows you to manage AWS EC2 InternetGateways which are used to enable communication between instances in your Virtual Private Cloud (VPC) and the internet.

Create a basic InternetGateway with a tag for identification.

import AWS from "alchemy/aws/control";
const internetGateway = await AWS.EC2.InternetGateway("myInternetGateway", {
Tags: [
{
Key: "Name",
Value: "MyInternetGateway"
}
]
});

Configure an InternetGateway to adopt an existing resource if it already exists.

const existingInternetGateway = await AWS.EC2.InternetGateway("existingGateway", {
adopt: true,
Tags: [
{
Key: "Environment",
Value: "Production"
}
]
});

Demonstrate how to attach the InternetGateway to a VPC for internet access.

import AWS from "alchemy/aws/control";
const myVpc = await AWS.EC2.Vpc("myVpc", {
CidrBlock: "10.0.0.0/16",
Tags: [
{
Key: "Name",
Value: "MyVPC"
}
]
});
const internetGateway = await AWS.EC2.InternetGateway("vpcInternetGateway", {
Tags: [
{
Key: "Name",
Value: "VPCInternetGateway"
}
]
});
// Attach the InternetGateway to the VPC
await AWS.EC2.AttachInternetGateway("attachGateway", {
InternetGatewayId: internetGateway.id,
VpcId: myVpc.id
});

Detach the InternetGateway from a VPC when no longer needed.

await AWS.EC2.DetachInternetGateway("detachGateway", {
InternetGatewayId: internetGateway.id,
VpcId: myVpc.id
});