Exercise
- Create a VPC with cidr range 10.100.0.0/16
- In this VPC create 4 subnets and then the cidr ranges can be
- 10.100.0.0/24 => web
- 10.100.1.0/24 => app
- 10.100.2.0/24 => db
- 10.100.3.0/24 => management
- Create Internet Gateway
- Create two route tables public and private
- Public route table associate with web and management and connect to internet gateway
- Private route table associate with app and db subnets and do not connect to internet gateway.

Solution
# Creating VPC
aws ec2 create-vpc --cidr-block '10.100.0.0/16'
# "VpcId": "vpc-0eba8022e1953c115"
# Create Web Sunet
aws ec2 create-subnet --vpc-id "vpc-0eba8022e1953c115" --cidr-block "10.100.0.0/24"
# "SubnetId": "subnet-0c243a6309b465f46"
# Create app Sunet
aws ec2 create-subnet --vpc-id "vpc-0eba8022e1953c115" --cidr-block "10.100.1.0/24"
# "SubnetId": "subnet-02b7aae980d15b6ad"
# Create db Sunet
aws ec2 create-subnet --vpc-id "vpc-0eba8022e1953c115" --cidr-block "10.100.2.0/24"
# "SubnetId": "subnet-0d391ef304b2c9a39"
# Create management Sunet
aws ec2 create-subnet --vpc-id "vpc-0eba8022e1953c115" --cidr-block "10.100.3.0/24"
# "SubnetId": "subnet-0e4f54626c7fe7836"
# Create igw
aws ec2 create-internet-gateway
# "InternetGatewayId": "igw-0bac78a54c832207b"
# Atttach igw to VPC
aws ec2 attach-internet-gateway --internet-gateway-id "igw-0bac78a54c832207b" --vpc-id "vpc-0eba8022e1953c115"
# Create public route table
aws ec2 create-route-table --vpc-id "vpc-0eba8022e1953c115"
# "RouteTableId": "rtb-0ab89bf233a402434"
# Create route from public subnet to igw
aws ec2 create-route --route-table-id "rtb-0ab89bf233a402434" --gateway-id "igw-0bac78a54c832207b" --destination-cidr-block "0.0.0.0/0"
# Attach Public Route table to Web Subnet
aws ec2 associate-route-table --route-table-id "rtb-0ab89bf233a402434" --subnet-id "subnet-0c243a6309b465f46"
# "AssociationId": "rtbassoc-0642624b29b6df071"
# Attach Public Route table to management Subnet
aws ec2 associate-route-table --route-table-id "rtb-0ab89bf233a402434" --subnet-id "subnet-0e4f54626c7fe7836"
# "AssociationId": "rtbassoc-07d2d5f7cf543c479"
# Create Private Route table
aws ec2 create-route-table --vpc-id "vpc-0eba8022e1953c115"
# "RouteTableId": "rtb-0c0c41cdd523fc8a9"
# Attach Private Route table to app Subnet
aws ec2 associate-route-table --route-table-id "rtb-0c0c41cdd523fc8a9" --subnet-id "subnet-02b7aae980d15b6ad"
# "AssociationId": "rtbassoc-0c5252c37222ba28b"
# Attach Private Route table to db Subnet
aws ec2 associate-route-table --route-table-id "rtb-0c0c41cdd523fc8a9" --subnet-id "subnet-0d391ef304b2c9a39"
# "AssociationId": "rtbassoc-04c8c8b7e00d16b4d"
Like this:
Like Loading...