Add internet access to a subnet - Amazon Virtual Private Cloud

Add internet access to a subnet

The following describes how to support internet access from a subnet in your VPC using an internet gateway. To remove internet access, you can detach the internet gateway from your VPC and then delete it.

1. Create an internet gateway

Use the following procedure to create an internet gateway.

To create an internet gateway
  1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/.

  2. In the navigation pane, choose Internet gateways.

  3. Choose Create internet gateway.

  4. (Optional) Enter a name for your internet gateway.

  5. (Optional) To add a tag, choose Add new tag and enter the tag key and value.

  6. Choose Create internet gateway.

  7. (Optional) To attach the internet gateway to a VPC now, choose Attach to a VPC from the banner at the top of the screen, select an available VPC, and then choose Attach internet gateway. Otherwise, you can attach your internet gateway to a VPC at another time.

2. Attach or detach an internet gateway from a VPC

To use an internet gateway, you must attach it to a VPC.

If you no longer need internet access for instances that you launch into a VPC, you can detach an internet gateway from a VPC. You can't detach an internet gateway if the VPC has resources with associated public IP addresses or Elastic IP addresses.

To attach or detach an internet gateway to a VPC
  1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/.

  2. In the navigation pane, choose Internet gateways.

  3. Select the check box for the internet gateway.

  4. To attach it, choose Actions, Attach to VPC, select an available VPC, and choose Attach internet gateway.

  5. To detach it, choose Actions, Detach from VPC and choose Detach internet gateway. When prompted for confirmation, choose Detach internet gateway.

3. Delete an internet gateway

If you no longer need an internet gateway, you can delete it. You can't delete an internet gateway if it's still attached to a VPC.

To delete an internet gateway
  1. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/.

  2. In the navigation pane, choose Internet gateways.

  3. Select the check box for the internet gateway.

  4. Choose Actions, Delete internet gateway.

  5. When prompted for confirmation, enter delete, and then choose Delete internet gateway.

API and command overview

You can perform the tasks described on this page using the command line or an API. For more information about the command line interfaces and a list of available API actions, see Working with Amazon VPC.

Create an internet gateway
Attach an internet gateway to a VPC
Describe an internet gateway
Detach an internet gateway from a VPC
Delete an internet gateway