Demystifying Public and Private Subnets in AWS VPC for Beginners : Naming or Configuration?

Today, we're going to embark on an exciting journey into the world of AWS, where we'll discover the magical realms of public and private subnets in something called a Virtual Private Cloud (VPC). Don't worry; I'll explain everything in a way that's super easy to understand.

What's an AWS VPC and Why Is It Cool? First things first, let's talk about VPC, which stands for Virtual Private Cloud. Imagine it like having your very own secret playground in a big park. This playground is isolated, which means it's all yours, and you get to decide who can come in and who can't. This is important because it helps keep your toys and games safe.

What's a Subnet? Now, imagine your secret playground is so big that you want to divide it into smaller areas, like having different sections for your toy cars, action figures, and stuffed animals. These smaller sections are like subnets. They help organize things and control where everything goes.

Meet the Characters: IGW and NAT Gateway Okay, now let's introduce our main characters: IGW and NAT Gateway.

IGW (Internet Gateway) : Think of the IGW as a magical door that connects your secret playground(VPC) to the outside world, just like how your front door connects your home to the neighborhood. When you want to show your toys to your friends outside, you use this door.

NAT Gateway (Network Address Translation Gateway): This one's a bit like a wizard who helps your toys send messages out to the world without revealing their secret hideout. When your toys want to talk to the world (the internet), they whisper their messages to the NAT Gateway, which then makes sure the messages look like they're coming from the NAT Gateway itself, not your toys. This way, your toys stay hidden and safe.

Route Table: The Traffic Boss Imagine if your playground had traffic rules to make sure everyone goes to the right place. That's what a route table does. It's like a map that tells the traffic (data) where to go. So, if your toy cars want to race in one part of the playground, the route table shows them the way there.

The Mystery of Public and Private Subnets Now, here's where it gets exciting! Sometimes, when you're setting up your secret playground (VPC), it's hard to tell which parts are public and which are private just by their names. That's because AWS lets you name them however you want, but the name alone doesn't always tell you their secrets.

Subnets: Inside your playground, there are smaller areas, like different parts of the playground where you put your toys. These areas are called subnets. Some subnets are for toys you want to share with your friends (public), and some are for toys you want to keep all to yourself (private).

Security Groups: Now, you also have some guards (security groups) in your playground. They make sure only the right toys can go to the right places. If a guard says, "You can't come in unless you're a friend," that's like a private area. If the guard says, "Everyone's welcome to come in and play," that's like a public area.

NAT Gateway: Sometimes, your toys need to send secret messages to their friends outside without anyone seeing where they are. This is where a NAT Gateway comes in. It's like a special helper that makes the messages look like they're coming from somewhere else, so your toys stay hidden.

Imagine a Mailman and a Magical Door:

Okay, so think of your computer like a house, and the internet is like a faraway land where you can send and receive messages, just like sending letters. Now, to help your computer talk to the internet, you have two special helpers: the Mailman (that's the NAT Gateway) and the Magical Door (that's the Internet Gateway).

Sending Messages (Outbound)

When your computer inside the house (a private subnet) wants to send a letter (data) to someone on the internet, it doesn't know how to get there on its own. So, it gives the letter to the Mailman. The Mailman (NAT Gateway) takes the letter and does something amazing! It changes the return address on the letter to its special address (a public IP). It's like if you sent a letter to your friend but put the Mailman's address instead of your own.

Now, with the changed address, the Mailman walks up to the Magical Door (Internet Gateway) and gives the letter to the door. The Magical Door knows how to send letters to the faraway land (the internet).

When someone from a faraway wants to send a letter back to your house, it first goes to the Magical Door (Internet Gateway). The Magical Door looks at the letter and says, "Hmm, this letter needs to go back to the house." So, it sends the letter to the Mailman (NAT Gateway) because it remembers that the Mailman knows which house it came from.

Now, the Mailman takes the letter, looks at the address on it, and says, "Aha! This letter belongs to the house." So, the Mailman changes the address back to your house's address (the original private IP).

Finally, the letter arrives back at your house, and your computer gets the message it was waiting for! So, you see, the Mailman (NAT Gateway) is super helpful, but it needs the Magical Door (Internet Gateway) to do its job. Without the Magical Door, the Mailman can't send letters to the faraway land (the internet), and your computer can't talk to the world. That's why they work together like a team, and the Internet Gateway is like the magical doorway to the Internet for both private and public areas in your computer world (VPC).

So, to sum it up, even though there's a magic door (Internet Gateway)attached to your entire playground (VPC), whether an area is public or private depends on the maps (route tables), guards (security groups), and helpers (NAT Gateway) you have inside that area. It's like having different rules for different parts of your playground, and that's how your toys can play safely in the cloud playground.

0
Subscribe to my newsletter

Read articles from Rasheed Bakare Abiola directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rasheed Bakare Abiola
Rasheed Bakare Abiola

Hello there! I'm Rasheed Bakare, a passionate DevOps Engineer with 2 years of hands-on experience in the exciting world of DevOps. My journey in the realm of technology has been a thrilling one, marked by a relentless pursuit of automation, efficiency, and innovation. ๐Ÿš€ Professional Experience ๐Ÿš€ Over the past two years, I've had the privilege of working in diverse environments and contributing to several high-impact DevOps projects. My work primarily revolves around crafting seamless and robust CI/CD pipelines, ensuring continuous integration and continuous delivery for software applications. I've had the opportunity to architect, implement, and optimize CI/CD workflows using tools like Jenkins, GitLab and CI/CD. ๐Ÿ”ง Tool Mastery ๐Ÿ”ง My toolkit is well-equipped with various DevOps technologies and practices. I've wielded Ansible and Terraform to orchestrate infrastructure as code (IaC), streamlining the provisioning and management of cloud resources. Docker and Kubernetes are my trusted companions when it comes to containerization and orchestration, enabling scalable and efficient deployments. Bash scripting and Python have been my allies in crafting automation solutions, from routine tasks to complex system configurations. ๐Ÿ’ก Passion for Learning ๐Ÿ’ก In the ever-evolving world of technology, I thrive on learning and staying ahead of the curve. I'm continuously exploring emerging DevOps trends, tools, and best practices to deliver optimal solutions. ๐Ÿค Freelance Projects ๐Ÿค Beyond my professional role, I've taken on exciting freelance DevOps projects. These experiences have allowed me to collaborate with a diverse range of clients, each with unique challenges and requirements. Whether it's automating deployment pipelines, optimizing infrastructure costs, or enhancing security postures, I relish the opportunity to make a meaningful impact. I'm a firm believer in the DevOps philosophy of breaking down silos, fostering collaboration, and delivering value faster to end-users. If you're looking for a DevOps Engineer who's passionate about automation, well-versed in the DevOps toolchain, and dedicated to driving efficiency and reliability, let's connect and explore how we can create exceptional technology solutions together. ๐Ÿ“ง Contact Me ๐Ÿ“ง Feel free to reach out to me at bakarerasheed.a38@gmail.com or connect with me on https://www.linkedin.com/in/bakare-rasheed-9307b0211 to discuss potential collaborations, share knowledge, or simply geek out about all things DevOps. Let's embark on this exciting DevOps journey together! ๐Ÿš€ #DevOps #CI/CD #Automation #InfrastructureAsCode #Containerization #Kubernetes #Cloud #Ansible #Terraform #BashScripting #Python #TechEnthusiast