What is AWS Internet Gateway and How we attached it to VPC from AWS Console as well as AWS CLI

An AWS Internet Gateway is a service that allows communication between resources within your Amazon Virtual Private Cloud (VPC) and the internet. It acts as a gateway between your VPC and the public internet, enabling instances within the VPC to access the internet and receive inbound traffic from the internet.

Here’s how you can attach an Internet Gateway to a VPC from both the AWS Management Console and AWS CLI:

Attaching an Internet Gateway to a VPC using the AWS Management Console:

Step 1: Sign in to the AWS Management Console.

Step 2: Open the Amazon VPC Dashboard by navigating to the “Services” menu, selecting “Networking & Content Delivery,” and then clicking on “VPC.”

Step 3: In the VPC Dashboard, click on “Internet Gateways” from the left-hand navigation pane.

Step 4: Click the “Create Internet Gateway” button and give it a meaningful name.

Step 5: Once the Internet Gateway is created, select it from the list, and in the “Actions” menu, choose “Attach to VPC.”

Step 6: A dialog box will appear, showing all your VPCs. Choose the VPC to which you want to attach the Internet Gateway and click “Attach.”

Attaching an Internet Gateway to a VPC using the AWS CLI:

To interact with AWS services via the AWS CLI, you don’t “login” to your AWS IAM account directly. Instead, you configure your AWS CLI with the necessary credentials (Access Key ID and Secret Access Key) for an IAM user or role that has the appropriate permissions to perform the desired actions, such as attaching an Internet Gateway to a VPC.

Here’s how you can attach an Internet Gateway to a VPC using the AWS CLI:

Step 1: Make sure you have AWS CLI installed and configured with the necessary IAM credentials. If you haven’t set up the AWS CLI yet, you can install it following the instructions for your operating system: https://aws.amazon.com/cli/

Step 2: Open your terminal or command prompt.

Step 3: Use the `create-internet-gateway` command to create an Internet Gateway as follow:

aws ec2 create-internet-gateway

Step 4: The command will return JSON output containing information about the newly created Internet Gateway, including its unique ID. Note down the ID for the next step.

Step 5: Use the `attach-internet-gateway` command to attach the Internet Gateway to a VPC, providing the Internet Gateway ID and VPC ID as follow:

aws ec2 attach-internet-gateway –internet-gateway-id YOUR_INTERNET_GATEWAY_ID –vpc-id YOUR_VPC_ID

Replace `YOUR_INTERNET_GATEWAY_ID` and `YOUR_VPC_ID` with the actual IDs you obtained in the previous steps.

After executing the `attach-internet-gateway` command, the Internet Gateway will be successfully attached to the specified VPC, and the resources within that VPC will be able to access the internet and receive inbound internet traffic. Remember, to perform these actions, the IAM user or role associated with your AWS CLI must have the necessary permissions to work with VPCs and Internet Gateways.

You also need to configure the route table to direct traffic to the Internet Gateway for internet access. Typically, this is done by adding a default route (`0.0.0.0/0`) pointing to the Internet Gateway in the main route table of your VPC.

If you really want to become an AWS Cloud Computing Expert , please refer the below website https://pravinmishra.in/

Hey Guys!!! Hope you like this post. Please share your views below.

1 thought on “What is AWS Internet Gateway and How we attached it to VPC from AWS Console as well as AWS CLI”

  1. Thank you for breaking down the process of attaching an AWS Internet Gateway to a VPC so clearly. Your step-by-step instructions for both the AWS Management Console and AWS CLI make it so easy to follow along. I’m feeling more confident in my AWS skills already! Looking forward to exploring more of your content. Keep up the excellent work!

Leave a Comment

Your email address will not be published. Required fields are marked *