Configuring an Amazon VPC
Published: 2023-12-07 11:35:19

A VPC(virtual private cloud) is an isolated portion of the AWS Cloud. You provision a VPC so that you can deploy AWS infrastructure services. It is a virtual network and, as such, it supports multiple subnets, routing, and fine-grained security mechanisms.

When you create a VPC, you define its IP address range, subnets, and route tables. You can also optionally use network gateways or hardware VPN solutions to securely connect it to on-premises corporate networks. 

Inside this virtual network, you can deploy AWS computing resources. These resources include, for example, Amazon Elastic Compute Cloud (Amazon EC2) or Amazon Relational Database Service (Amazon RDS) instances. You can also define how—and whether—your private network space connects to endpoints in your network topology. A VPC can span multiple Availability Zones.


![creating a vpc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exxsqw27g3jzzeu80jz0.png)

##  key component Of A VPC


- **Subnet**–Subnets are logical network segments within your VPC. They enable you to subdivide your VPC network into smaller networks inside a single Availability Zone. A subnet is publicif it is attached to an internet gateway, or privateif it is not.

- **Security group** –A security group is a set of firewallrules that secure instances. They allow or block inbound and outbound traffic into an instance (stateful).

- **Primary network interface (elastic network interface)** –An elastic network interface is a virtual network interface (NIC) that connects an instance to a network.

- **Router**–A router is a component that routes traffic within the VPC.

- **Internet gateway** –An internet gateway is a VPC component that enables communication between instances in a VPC and the internet. 

- **Virtual private gateway**  –A virtual private gateway is the component that is defined on the AWS side of a virtual private network(VPN) connection. 

- **Customer gateway** –A customer gateway is a physical device or software application that is defined on the client side of a VPN connection

## HOW TO CONFIGURE AWS VPC

**Task 1: Creating a VPC**


On the AWS Management Console, in the Search bar, enter and choose **VPC** to go to the VPC Management Console.

In the left navigation pane, for Virtual private cloud, choose **Your VPCs**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b1ewmbkb03r2ve1u1lg8.PNG)
 In every Region, a default VPC with a Classless Inter-Domain Routing (CIDR) block of 172.31.0.0/16 has already been created for you. Even if you haven't created anything in your account yet, you will see some pre-existing VPC resources already there.

Choose **Create VPC** and configure the following options:

Resources to create: Choose **VPC only.**

Name tag: Enter **Lab VPC.**

IPv4 CIDR block: Choose **IPv4 CIDR manual input**.

IPv4 CIDR: Enter **10.0.0.0/16**.

IPv6 CIDR block: Choose **No IPv6 CIDR block**.

Tenancy: Choose **Default**.

Tags: Leave the suggested tags as is.

Choose **Create VPC**. 

![creating a vpc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aaaffpcg9tqfjwqb0x89.PNG)

![creating a vpc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2n4u6b5n3nq269mvrcjo.PNG)

At the top of the page, a message displays similar to the following: "You successfully created vpc-NNNNNNNNNNN / Lab VPC."

Choose **Actions**, and choose **Edit VPC settings.**

In the DNS settings section, select **Enable DNS hostnames**.

Choose **Save**.

EC2 instances launched into the VPC now automatically receive a public IPv4 Domain Name System (DNS) hostname.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzf7bhn1w5lo13ih0v86.PNG)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oe8oz9klviow8afsg27w.PNG)

# Task 2: Creating subnets

## Task 2.1: Creating a public subnet
In the left navigation pane, for Virtual private cloud, choose **Subnets**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5hstcb63aelpvbxuyqk.PNG)

Choose **Create subnet** and configure the following options:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy0uoyl7kpt8hmp8tcn4.PNG)

VPC ID: Choose **Lab VPC**.

Subnet name: Enter **Public Subnet**.

Availability Zone: Choose the first Availability Zone in the list. Do not choose No preference.

IPv4 CIDR block: Enter **10.0.0.0/24**.

Choose **Create subnet**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iaj69dydab1dkk9vi6r5.PNG)

You now configure the public subnet to automatically assign a public IP address for all EC2 instances that are launched within it.

Select **Public Subnet**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzc1ted9tu80mxwt9jcj.PNG)

Choose **Actions**, and then choose **Edit subnet settings**.

In the Auto-assign IP settings section, select **Enable auto-assign public IPv4 address**.

Choose **Save**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zwhjers3rmd41wcy1bcv.PNG)

 Even though this subnet has been named Public Subnet, it is not yet public. A public subnet must have an internet gateway, which you attach in a task later in the lab.