This guide provides step-by-step instructions for creating and managing an Internet Gateway using AWS CLI.
This guide assumes you have AWS CLI configured on your system with appropriate IAM permissions.
To create an Internet Gateway, use the following command:
aws ec2 create-internet-gateway --query InternetGateway.InternetGatewayId --output text

Once the Internet Gateway is created, confirm the successful creation and retrieve the Internet Gateway ID for the next steps.

Next, check your VPC and retrieve the VPC ID to use in subsequent commands:

Attach the Internet Gateway to your VPC by using the following command:
aws ec2 attach-internet-gateway --vpc-id <VPC-ID> --internet-gateway-id <IGW-ID>

Create a Route Table for the VPC:
aws ec2 create-route-table --vpc-id <VPC-ID> --query RouteTable.RouteTableId --output text
After creating the route table, create a route for the Internet Gateway:
aws ec2 create-route --route-table-id <RTB-ID> --destination-cidr-block 0.0.0.0/0 --gateway-id <IGW-ID>
Check the route table:
aws ec2 describe-route-tables --route-table-id <RTB-ID>
Finally, associate the route table with a Subnet:
aws ec2 associate-route-table --subnet-id <Subnet-ID> --route-table-id <RTB-ID>
Make sure to replace placeholders like <VPC-ID>, <IGW-ID>, <RTB-ID>, and <Subnet-ID> with actual values from your AWS environment.
By following the steps in this guide, you can successfully create and manage an Internet Gateway in AWS. The Internet Gateway allows your VPC to communicate with the Internet, enabling inbound and outbound traffic for your resources.