How to create a custom VPC on AWS

Mathildaduku
6 min readJan 16, 2023

Hi guys, I’ll be showing you how to set up your own VPC on AWS. At the end of this article you should be able to create a VPC, attach it to an internet gateway, create route tables and subnets.

What is a VPC?

VPC is an acronym for Virtual Private Cloud and like the name implies it is a secluded cloud designated for you. It is a secure, isolated private cloud hosted within a public cloud. You have the freedom to customize it however you like, almost like your own datacenter, that’s really cool. You can host your own services and manage the traffic going in and out of your network. Okay lets create one real quick, I promise it won’t take time.

Were going to be doing this using AWS as our cloud provider so you should be logged in on your AWS console. Don’t have an account, create a free one here.

Create a custom VPC

Click on services and search for VPC, click create VPC, select VPC only, give it your desired name.

Next we will assign a CIDR block of IP addresses to your VPC, this is you basically defining a block of IP addresses that you’d use within your virtual private cloud(VPC), you want to make sure you choose enough IP addresses because after creating the VPC you cant go back to change it. So I chose 10.0.0.0/16 which provides 65,536 IP addresses. Leave everything as default and click create VPC.

Click on your VPC and select edit VPC settings. Select enable DNS hostnames and save

Create an internet gateway

Now we have our VPC but we need access to the internet, an internet gateway would help with that so you guessed it right, we have to create an internet gateway. Click on internet gateway and create internet gateway. Give it a name and click create.

We have an internet gateway and a VPC but they don’t know each other, so we have to bring them together so they can be one happy family. We do that by attaching the internet gateway to the VPC. Click attach to VPC and select the VPC we just created and click attach.

Create subnets

Now we are going to need subnets within our VPC, this is going to allow us divide our network into various parts. When setting up a network you should know the number of subnets you need. I want 4 subnets (2 public subnets and 2 private subnets) so I’m going to divide my CIDR block (10.0.0.0/16) into 4 parts and also make sure they don’t overlap each other to avoid any discrepancies. Now we have these 4 subnets to work with 10.0.0.0/18, 10.0.64.0/18, 10.0.128.0/18, 10.0.128.0/18 and 10.0.192.0/18. Leave a comment if you want a tutorial on dividing your network.

Now click create subnet, select the VPC we created, I’ll be using 2 availability zones(AZ), this is the physical location where AWS servers are located. A public and private subnet would be placed in one AZ(us-east-1a) and the other public and private subnet would be placed in the second AZ(us-east-1b).

Create route tables

To ensure data within our network is sent to the the right locations, we need to create and configure route tables and assign it to our subnets. We need a separate route table for our public and private subnet because we want the public subnets to be reachable on the internet and the private subnets to not be reachable on the internet and be a completely private space and we can’t achieve that if both subnets are using the same route table, hence the need for separate route tables.

Click create route table, give the route table a name, and select the VPC we created, click create route table.

We have our private and public route table, now we need associate these route tables to their respective subnets. Select the private route table, click edit subnet associations, choose ONLY the private subnets you created, click save associations.

Repeat the same process for the public route table, but this time, you’d be choosing the public subnets ONLY.

Both route tables are completely excluded from the internet, but we don’t want that for our public route table, we want it to be reachable on the internet. I mean isn’t that why it’s called “public”? It’s an extrovert. Now remember that internet gateway we created earlier? Yep, its time to put it to good use.

Go to your public route table, click edit routes, click add routes, under destination type 0.0.0.0/0 under target search for “internet gateway”, select the internet gateway earlier created, click save changes and we’re done. your subnets are now actually “public”.

Conclusion

Congratulations you’ve created your first custom VPC on AWS. What next? you can now create EC2 instances and other resources within your public or private subnets, don’t know how to do that? Don’t worry I got you, check out the next post I’ve linked here to learn how to deploy a web server on private instances and how to use a load balancer.

Thank you for reading my first blog post, please subscribe and share to anyone who might be interested and leave a comment if you have any questions or feedback. Until next time, ciao!!!!

--

--