1. Answers
  2. Creating an AWS EC2 Internet Gateway

How do I create an AWS EC2 Internet Gateway?

In this guide, we will create an Internet Gateway for an AWS EC2 instance using Pulumi. An Internet Gateway is a horizontally scaled, redundant, and highly available VPC component that allows communication between instances in your VPC and the internet.

Key Points

  • We will create a VPC (Virtual Private Cloud).
  • We will create an Internet Gateway.
  • We will attach the Internet Gateway to the VPC.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create a VPC
const vpc = new aws.ec2.Vpc("myVpc", {
    cidrBlock: "10.0.0.0/16",
    tags: {
        Name: "myVpc",
    },
});

// Create an Internet Gateway
const internetGateway = new aws.ec2.InternetGateway("myInternetGateway", {
    vpcId: vpc.id,
    tags: {
        Name: "myInternetGateway",
    },
});

// Export the IDs of the VPC and Internet Gateway
export const vpcId = vpc.id;
export const internetGatewayId = internetGateway.id;

Summary

In this guide, we created a VPC and an Internet Gateway using Pulumi. We then attached the Internet Gateway to the VPC, allowing instances within the VPC to communicate with the internet. The IDs of the created VPC and Internet Gateway are exported for further use.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up