Skip to content

Lab · Cloud Computing (AWS, Azure, Google Cloud)

Lab: plan and build a VPC for a pharmacy app

Labbeginner· about 1.5 hours· 4 steps

The brief

MediPlus, a pharmacy chain in Maharashtra, needs a private network in AWS Mumbai for its ordering app: public subnets for the load balancer and private subnets for the app and database, in two availability zones. Plan the address ranges in Python, check them, then create the VPC and two subnets (free) and delete them again.

Why it matters

Every company network in the cloud starts with an IP plan, and mistakes are painful to fix later: overlapping ranges cannot be connected, and subnets that are too small run out of addresses. Network and cloud engineers plan CIDR ranges in a spreadsheet or a script like this before anything is built.

Skills you practise

  • CIDR notation
  • splitting a /16 into /24 subnets
  • the 5 reserved addresses per AWS subnet
  • overlap checks with ipaddress
  • aws ec2 create-vpc, create-subnet and describe-subnets
  • deleting what you built

You need

  • A free AWS account with a budget alert set (lab cc-lab-safe-account)
  • AWS CLI v2 configured with an IAM Identity Center or IAM user profile, not root, region ap-south-1 (or AWS CloudShell in Mumbai)

What you will have at the end

vpc_plan.py, which plans and checks subnets for any number of zones, plus pasted proof that the planned VPC was built in Mumbai and then deleted.

How it is marked (rubric, 100 points)
Correct planplan_subnets and check_plan pass every check, including overlaps, ranges outside the VPC and the 5 reserved addresses.40
Built as plannedThe subnets matched the plan and were in two different zones.25
Cleaned upThe subnets and the VPC were deleted, in the right order.20
Can explainYou can say why a public subnet alone does not make a server reachable, and why the database goes in a private subnet.15

0/4 steps done

Step 1 of 4

Split the VPC into subnets

plan_subnets(vpc_cidr, zones) gives one public and one private /24 per zone, taken in order from the VPC range.

A VPC of 10.0.0.0/16 has 65,536 addresses. You cut it into /24 subnets of 256 addresses each: 10.0.0.0/24, 10.0.1.0/24, and so on. Each subnet lives in one availability zone, so for two zones you need a public and a private subnet in each.

ipaddress.ip_network(cidr).subnets(new_prefix=24) gives the /24 blocks in order; next() takes the next one. Hand out all the public subnets first, then the private ones, and name each "public-ap-south-1a" and so on.

Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.