How to Setup a VPC in AWS

How to Setup a VPC in AWS
How to Setup a VPC in AWS

What is a VPC in AWS?

Before going in-depth, firstly, you need to know what a VPC is. VPC stands for Virtual Private Cloud. Amazon Virtual Private Cloud (Amazon VPC) enables you to launch AWS resources into a virtual network that you've defined. This virtual network closely resembles a traditional network that you'd operate in your own data centre, with the benefits of using the scalable infrastructure of AWS. It is the most significant security boundary provided by Amazon Web Services. AWS provides you with a web-based user interface to create your VPC.

You will need to create an Amazon Web Services account to access your AWS console or dashboard and create your VPC. These are the specific terminology you need to be familiar with before starting this VPC tutorial:

VPC:  the virtual private cloud that creates an isolated network on the cloud for your resources.

  • Subnet: this is the range of IP addresses that you have available in your VPC
  • Route table: these are rules that determine where your network traffic will go
  • Internet gateway: The internet gateway will connect your virtual private cloud resources to the internet and between your resources
  • VPC endpoint: A VPC endpoint enables private connections between your VPC and supported AWS services

How to Setup a VPC in AWS

In this scenario we will launch two EC2 instances, in which you will use one for an application (APP) server and the other for a database (DB) server. The APP server EC2 instance will be accessible through the internet IP address. We will then connect the database server with the application server internally by using a VPC subnet. The DB Server will not be accessible over the internet for security reasons. Let's get started.

Create a VPC:

  1. First of all, you need to log in to your AWS account; then, you need to reach for “Select VPC” from the services tab. There you need to choose your VPC and click on “Create VPC.”
  1. The next step is to specify a name for your VPC and classless inter-domain routing (CIDR) block. Then you click on the “yes, create” option to create it.

Create VPC subnets:

If you want to create the subnets, then you will need to follow the below-mentioned steps. Let’s have a look.

  1. Click on the “subnets” option in the VPC dashboard and then click “create subnet” to continue
  2. Enter the information required.
  1. Click on “yes, create” to confirm the creation of the subnet. You can use this procedure to create as many subnets as you require.

Create a route table:

  1. Now we will create a route table. Go to the VPC dashboard again, and click on “create route table”
  2. Then you need to enter the route table name and select your VPC.

Create an internet gateway:

  1. We will now create an internet gateway, click 'internet gateway' on the left and click 'create internet gateway'
  2. Enter the name of the gateway and click 'yes, create gateway.
  1. After creating the gateway, you will need to attach it to your VPC. To do this, you need to select the gateway that you want to connect and then right-click on it to get the option “attach to VPC.”
  1. The next step is to add a route to the route table that you created previously. For this, you need to go to the route tables area, and then select your route table
  2. After selecting your route table, you need to click on the route tab and then select the edit option and click on “add another route”
  3. Then you need to enter the destination IP address of the internet. And then, your desired internet gateway will be populated automatically.
  1. Then you need to click on the “save” option to confirm the changes.

Change route table for VPC subnet:

Now, it is time to change the routeing table for your VPC subnet.

  1. Go to the VPC dashboard and select the VPC that you want to change the routeing table for.
  2. Click on the “route table” option and then select the edit option.
  1. Now, you need to change the default route table to “LNX-RouteTable” and then hit on save option.

Launch the APP and a DB Server Instance in the VPC:

If you created two subnets previously, you will need to launch the APP server in one subnet, subnet1, and the DB server using the other subnet, subnet2.

You now need to try to SSH APP server through its public IP.

  • You will notice that the DB server is not connected to the internet, for security reasons and because we launched it through subnet2 using its default route table. Because the internet gateway was not associated with the route Table of subnet2, we cannot access it through the internet.

Last words

Setting up yuour VPC in Amazon Web Services is a relatively simple thing to do. However you still need to be very careful when setting things up as small mistakes can lead to security problems.

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.