اس کیپ اسٹون میں آپ AWS میں production-style VPC بنائیں گے — پبلک اور پرائیویٹ سب نیٹس، آگے ALB، سیکیورٹی گروپس اور NACLs، اور Flow Logs — سخت cost hygiene کے ساتھ۔
Is capstone mein aap AWS mein production-style VPC banayenge — public aur private subnets, aage ALB, security groups aur NACLs, aur Flow Logs — sakht cost hygiene ke saath.
In this capstone you will build a production-style AWS VPC with public and private subnets, an ALB in front, security groups and NACLs, and Flow Logs — with strict cost hygiene.
یہ ایسے ہے جیسے ایک دکان ہو جس میں کھلا شوروم اور بند گودام ہو: گاہک شوروم (public subnets) میں آزادانہ آ سکتے ہیں، لیکن اسٹاک روم (private subnets) تک صرف اسٹاف والے راستے (NAT گیٹ وے) سے پہنچا جا سکتا ہے۔
Yeh aisa hai jaise ek dukan ho jis mein khula showroom aur band godam ho: gahak showroom (public subnets) mein aazadana aa sakte hain, lekin stock room (private subnets) tak sirf staff wale raaste (NAT gateway) se pahuncha ja sakta hai.
This is like a shop with a public showroom and a locked warehouse: customers enter the showroom (public subnets) freely, but the stock room (private subnets) is reached only through a staff-only corridor (NAT gateway).

آپ کو AWS فری ٹیئر کا اکاؤنٹ اور ایک ریجن (us-east-1 استعمال کریں) درکار ہے۔ نیچے تمام IDs subnet-0123456789abcdef0 طرز کی مثالی IDs ہیں — اپنے کنسول آؤٹ پٹ سے اصلی IDs کاپی کریں۔
Aap ko AWS free tier ka account aur ek region (us-east-1 istemal karein) darkar hai. Neeche tamam IDs subnet-0123456789abcdef0 tarz ki misali IDs hain — apne console output se asli IDs copy karein.
You need an AWS free-tier account and one region (use us-east-1). All IDs below are examples in the style subnet-0123456789abcdef0 — copy real IDs from your own console output.
VPC (10.10.0.0/16) بنائیں جس میں دو AZs میں دو پبلک سب نیٹس اور انہی AZs میں دو پرائیویٹ سب نیٹس ہوں۔ دو AZs آپ کو محفوظ رکھتے ہیں اگر ایک زون فیل ہو جائے۔
VPC (10.10.0.0/16) banayen jis mein do AZs mein do public subnets aur unhi AZs mein do private subnets hon. Do AZs aap ko mehfooz rakhte hain agar ek zone fail ho jaye.
Create the VPC (10.10.0.0/16) with two public subnets in two AZs and two private subnets in the same AZs. Two AZs keep you resilient if one zone fails.
aws ec2 create-vpc --cidr-block 10.10.0.0/16 --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=netsec-vpc}]'aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 --cidr-block 10.10.1.0/24 --availability-zone us-east-1a --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=public-a}]'aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 --cidr-block 10.10.2.0/24 --availability-zone us-east-1b --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=public-b}]'aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 --cidr-block 10.10.11.0/24 --availability-zone us-east-1a --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=private-a}]'aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 --cidr-block 10.10.12.0/24 --availability-zone us-east-1b --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=private-b}]'🖱️ کنسول میں جائیںConsole mein jayenVPC > Your VPCs > Create VPC
VPC کے ساتھ ایک Internet Gateway attach کریں اور پبلک روٹ ٹیبل کے default route (0.0.0.0/0) کو اسی کی طرف موڑیں۔ یہ روٹ صرف پبلک سب نیٹس کو ملتا ہے — پرائیویٹ سب نیٹس پوشیدہ رہتے ہیں۔
VPC ke saath ek Internet Gateway attach karein aur public route table ke default route (0.0.0.0/0) ko isi ki taraf morhen. Yeh route sirf public subnets ko milta hai — private subnets poshida rehte hain.
Attach an Internet Gateway to the VPC and point the public route table's default route (0.0.0.0/0) at it. Only the public subnets get this route — the private ones stay hidden.
aws ec2 create-internet-gateway --tag-specifications 'ResourceType=internet-gateway,Tags=[{Key=Name,Value=netsec-igw}]'aws ec2 attach-internet-gateway --vpc-id vpc-0123456789abcdef0 --internet-gateway-id igw-0123456789abcdef0aws ec2 create-route-table --vpc-id vpc-0123456789abcdef0 --tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=public-rt}]'aws ec2 create-route --route-table-id rtb-0123456789abcdef0 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-0123456789abcdef0aws ec2 associate-route-table --route-table-id rtb-0123456789abcdef0 --subnet-id subnet-0123456789abcdef0🖱️ کنسول میں جائیںConsole mein jayenVPC > Internet gateways > Create internet gateway
ایک پبلک سب نیٹ میں NAT گیٹ وے بنائیں تاکہ پرائیویٹ ورک لوڈز اپ ڈیٹس کے لیے انٹرنیٹ تک پہنچ سکیں لیکن خود انٹرنیٹ سے پوشیدہ رہیں۔ COST WARNING: NAT گیٹ وے ہر گھنٹے اور ڈیٹا کی قیمت لیتا ہے — اس لیب کے فوراً بعد اسے ڈیلیٹ کر دیں۔
Ek public subnet mein NAT gateway banayen taake private workloads updates ke liye internet tak pahunch saken lekin khud internet se poshida rahen. COST WARNING: NAT gateway har ghante aur data ki qeemat leta hai — is lab ke foran baad ise delete kar dein.
Create a NAT gateway in a public subnet so private workloads can reach the internet for updates without being reachable themselves. COST WARNING: the NAT gateway is billed per hour plus data — delete it right after this lab.
aws ec2 allocate-address --domain vpcaws ec2 create-nat-gateway --subnet-id subnet-0123456789abcdef0 --allocation-id eipalloc-0123456789abcdef0 --tag-specifications 'ResourceType=natgateway,Tags=[{Key=Name,Value=netsec-nat}]'aws ec2 create-route-table --vpc-id vpc-0123456789abcdef0 --tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=private-rt}]'aws ec2 create-route --route-table-id rtb-0123456789abcdef1 --destination-cidr-block 0.0.0.0/0 --nat-gateway-id nat-0123456789abcdef0🖱️ کنسول میں جائیںConsole mein jayenVPC > NAT gateways > Create NAT gateway
سیکیورٹی گروپس بنائیں: web-sg کہیں سے بھی HTTPS کی اجازت دیتا ہے، app-sg صرف web-sg سے ٹریفک کی اجازت دیتا ہے۔ پھر پبلک سب نیٹس کے لیے ایک NACL بنائیں۔ دفاع کی دو پرتیں — دربان اور turnstile دونوں۔
Security groups banayen: web-sg kahin se bhi HTTPS ki ijazat deta hai, app-sg sirf web-sg se traffic ki ijazat deta hai. Phir public subnets ke liye ek NACL banayen. Difa ki do paraten — darban aur turnstile dono.
Create security groups: web-sg allows HTTPS from anywhere, app-sg allows traffic only from web-sg. Then create a NACL for the public subnets. Two layers of defence — the bouncer and the turnstile.
aws ec2 create-security-group --group-name web-sg --description 'web tier' --vpc-id vpc-0123456789abcdef0aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 443 --cidr 0.0.0.0/0aws ec2 create-security-group --group-name app-sg --description 'app tier' --vpc-id vpc-0123456789abcdef0aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef1 --protocol tcp --port 8080 --source-group sg-0123456789abcdef0aws ec2 create-network-acl --vpc-id vpc-0123456789abcdef0 --tag-specifications 'ResourceType=network-acl,Tags=[{Key=Name,Value=public-nacl}]'🖱️ کنسول میں جائیںConsole mein jayenVPC > Security groups > Create security group
دونوں پبلک سب نیٹس میں web-sg کے ساتھ ایک Application Load Balancer بنائیں۔ نوٹ: ALB بھی ہر گھنٹے کی قیمت لیتا ہے — اسے ٹیسٹ کریں، پھر آخر میں NAT گیٹ وے کے ساتھ ڈیلیٹ کر دیں۔
Dono public subnets mein web-sg ke saath ek Application Load Balancer banayen. Note: ALB bhi har ghante ki qeemat leta hai — ise test karein, phir aakhir mein NAT gateway ke saath delete kar dein.
Create an Application Load Balancer across both public subnets with web-sg attached. Note: the ALB is also billed per hour — test it, then delete it with the NAT gateway at the end.
aws elbv2 create-load-balancer --name netsec-alb --subnets subnet-0123456789abcdef0 subnet-0123456789abcdef1 --security-groups sg-0123456789abcdef0aws elbv2 create-target-group --name netsec-tg --protocol HTTP --port 80 --vpc-id vpc-0123456789abcdef0🖱️ کنسول میں جائیںConsole mein jayenEC2 > Load Balancers > Create load balancer
CloudWatch تک VPC Flow Logs فعال کریں تاکہ آپ ہر allowed اور rejected packet دیکھ سکیں۔ یہ آپ کی CCTV فوٹیج ہے — اس کے بغیر آپ اندھوں کی طرح troubleshooting کریں گے۔
CloudWatch tak VPC Flow Logs fa-aal karein taake aap har allowed aur rejected packet dekh saken. Yeh aap ki CCTV footage hai — is ke baghair aap andhon ki tarah troubleshooting karenge.
Enable VPC Flow Logs to CloudWatch so you can see every allowed and rejected packet. This is your CCTV footage — without it you are troubleshooting blind.
aws logs create-log-group --log-group-name netsec-flowlogsaws ec2 create-flow-logs --resource-type VPC --resource-ids vpc-0123456789abcdef0 --traffic-type ALL --log-destination-type cloud-watch-logs --log-group-name netsec-flowlogs --deliver-logs-permission-arn arn:aws:iam::123456789012:role/flowlogs-role🖱️ کنسول میں جائیںConsole mein jayenVPC > Your VPCs > select VPC > Flow Logs tab > Create flow log
صفائی: ALB ڈیلیٹ کریں، NAT گیٹ وے ڈیلیٹ کریں اور Elastic IP ریلیز کریں، پھر VPC ڈیلیٹ کر دیں۔ فری ٹیئر بھولے ہوئے billed ریسورسز کو معاف نہیں کرتا۔
Safai: ALB delete karein, NAT gateway delete karein aur Elastic IP release karein, phir VPC delete kar dein. Free tier bhoole hue billed resources ko maaf nahi karta.
Clean up: delete the ALB, the NAT gateway and release the Elastic IP, then delete the VPC. Free tier does not forgive forgotten billed resources.
aws elbv2 delete-load-balancer --load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/netsec-alb/0123456789abcdefaws ec2 delete-nat-gateway --nat-gateway-id nat-0123456789abcdef0aws ec2 release-address --allocation-id eipalloc-0123456789abcdef0🖱️ کنسول میں جائیںConsole mein jayenVPC > Your VPCs > select VPC > Delete VPC
ALB کے DNS نام پر curl کریں اور بیک اینڈ سے جواب حاصل کریں، پھر netsec-flowlogs کے نیچے CloudWatch Logs میں اپنے ٹیسٹ ٹریفک کے ACCEPT اور REJECT اندراجات دیکھیں۔
ALB ke DNS name par curl karein aur backend se jawab hasil karein, phir netsec-flowlogs ke neeche CloudWatch Logs mein apne test traffic ke ACCEPT aur REJECT entries dekhen.
Curl the ALB DNS name and get a response from the backend, then check CloudWatch Logs under netsec-flowlogs to see the ACCEPT and REJECT entries for your test traffic.
aws ec2 describe-flow-logs --filter Name=resource-id,Values=vpc-0123456789abcdef0aws elbv2 describe-target-health --target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/netsec-tg/0123456789abcdef