DevOps Bootcamp · Lesson

Networking: VPCs, Subnets & Security Groups

Stand up cloud network resources.

Lesson 3 of 413 steps

Networking: VPCs, Subnets & Security Groups is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

Servers Need a Network

Before an instance can talk to anything, it needs a network home: a private network, a subnet, and firewall rules. Ansible builds all three. 🌐

Start With a VPC

A VPC is your isolated private network in AWS. The ec2_vpc_net module creates one from a CIDR block you choose.

amazon.aws.ec2_vpc_net:
  name: app-vpc
  cidr_block: 10.0.0.0/16

CIDR Defines the Address Range

The cidr_block sets how many private IPs the VPC owns. A /16 gives roughly 65,000 addresses to carve up.

Carve Out a Subnet

A subnet is a slice of the VPC, usually one per availability zone. ec2_vpc_subnet creates it inside the VPC.

amazon.aws.ec2_vpc_subnet:
  vpc_id: "{{ vpc.vpc.id }}"
  cidr: 10.0.1.0/24

Public vs Private Subnets

A subnet is public when its routes reach an internet gateway. Otherwise it is private, hidden from the open internet.

Security Groups Are Firewalls

A security group is a stateful firewall around your instances. ec2_security_group defines exactly which traffic is allowed in.

amazon.aws.ec2_security_group:
  name: web-sg
  description: web tier
  vpc_id: "{{ vpc.vpc.id }}"

Allow Inbound Rules

The rules list opens ports. Here you let HTTP reach the web tier from anywhere on the internet.

rules:
  - proto: tcp
    ports: [80]
    cidr_ip: 0.0.0.0/0

Lock Down SSH

Restrict port 22 to your own IP, not the whole world. A tight cidr_ip keeps attackers off your servers.

rules:
  - proto: tcp
    ports: [22]
    cidr_ip: 203.0.113.5/32

Wire It All Together

Register the VPC, pass its id to the subnet and security group, then attach that group to your EC2 instance. Everything connects by id.

amazon.aws.ec2_instance:
  name: web-01
  security_groups: [web-sg]
  vpc_subnet_id: "{{ subnet.subnet.id }}"

Order and Idempotency

Build network resources before the instance, and like all cloud modules they are idempotent, so re-running the play is safe.

Reach the Internet With a Gateway

An internet gateway lets a public subnet send traffic out. The ec2_vpc_igw module attaches one to your VPC.

amazon.aws.ec2_vpc_igw:
  vpc_id: "{{ vpc.vpc.id }}"
  state: present

Quick Check

You want only HTTP traffic to reach your web servers. Which resource controls that?

Recap

You built the network: a VPC for isolation, a subnet for placement, and a security group firewall, then attached them to your instance. ✨

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Networking: VPCs, Subnets & Security Groups” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Networking: VPCs, Subnets & Security Groups”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Networking: VPCs, Subnets & Security Groups”?

Stand up cloud network resources. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

How long does the “Networking: VPCs, Subnets & Security Groups” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Cloud Collections & Authentication
  2. Launch EC2 Instances Declaratively
  3. Networking: VPCs, Subnets & Security Groups
  4. Provision Then Configure in One Flow
← Back to DevOps Bootcamp