AWS Command Line Example to configure VPC

Tasks to perform:

1. Create VPC with a CIDR block of 10.0.0.0/16.
2. Create Public and Private Subnets in 4 availability zones and Tag them.
3. Change Public subnet IPv4 addressing behavior (auto-assign public IPv4).
4. Create Internet gateway, tag it and attach it to VPC.
5. Create Public Route Table and Tag them.
6. Tag main Route Table
7. Create Route entry for internet gateway.
8. Associate Public Subnets with Public Route Table and Private Subnets with Private Route Table. 

Note: Change Resource Id's with your Respective Resource Id's (eg: vpc-xxxxxxx, subnet-xxxxxxx, rtb-xxxxxxx)

1.Create VPC with CIDR block 10.0.0.0/16

#aws ec2 create-vpc --cidr-block 10.0.0.0/16
#aws ec2 create-tags --resources vpc-001c305ff96094653 --tags Key=Name,Value=My-VPC

2.Create two public subnets and Tag them

#aws ec2 create-subnet --vpc-id vpc-001c305ff96094653 --cidr-block 10.0.0.0/24 --availability-zone us-east-1a
#aws ec2 create-tags --resources subnet-0e5d976ddcf99803e --tags Key=Name,Value=Public-1a
#aws ec2 create-subnet --vpc-id vpc-001c305ff96094653 --cidr-block 10.0.1.0/24 --availability-zone us-east-1b
#aws ec2 create-tags --resources subnet-0fa40143d62ee153f --tags Key=Name,Value=Public-1b

3.Create two private subnets and Tag them

#aws ec2 create-subnet --vpc-id vpc-001c305ff96094653 --cidr-block 10.0.2.0/24 --availability-zone us-east-1c
#aws ec2 create-tags --resources subnet-08101fac2b2a63a49 --tags Key=Name,Value=Private-1c
#aws ec2 create-subnet --vpc-id vpc-001c305ff96094653 --cidr-block 10.0.3.0/24 --availability-zone us-east-1d
#aws ec2 create-tags --resources subnet-057a3aca47b2b74c9 --tags Key=Name,Value=Private-1d

4.Change a subnet's public IPv4 addressing behavior

#aws ec2 modify-subnet-attribute --subnet-id subnet-0e5d976ddcf99803e --map-public-ip-on-launch
#aws ec2 modify-subnet-attribute --subnet-id subnet-0fa40143d62ee153f --map-public-ip-on-launch

5.Create Internet Gateway For VPC

#aws ec2 create-internet-gateway
#aws ec2 create-tags --resources igw-07de90cac62aeb974 --tags Key=Name,Value=My-IGW

6.Attach Internet Gateway to VPC 

#aws ec2 attach-internet-gateway --internet-gateway-id igw-07de90cac62aeb974 --vpc-id vpc-001c305ff96094653

7.Create Public Route Table 

#aws ec2 create-route-table --vpc-id vpc-001c305ff96094653
#aws ec2 create-tags --resources rtb-0bd1ddee351f41843 --tags Key=Name,Value=PublicRT

8.Create Tag for Main RouteTable(Private RouteTable)  

#aws ec2 create-tags --resources rtb-06928448f0a014e32 --tags Key=Name,Value=PrivateRT

9.Create a route for Internet Gateway

#aws ec2 create-route --route-table-id rtb-0bd1ddee351f41843 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-07de90cac62aeb974

10.Describe a Route Table

#aws ec2 describe-route-table --route-table-id rtb-0bd1ddee351f41843 

11.Associate Public Subnet with Public RouteTable  

#aws ec2 associate-route-table --route-table-id rtb-0bd1ddee351f41843 --subnet-id subnet-0e5d976ddcf99803e
#aws ec2 associate-route-table --route-table-id rtb-0bd1ddee351f41843 --subnet-id subnet-0fa40143d62ee153f

12.Associate Private Subnet with Main RouteTable(Private RouteTable)  

#aws ec2 associate-route-table --route-table-id rtb-06928448f0a014e32 --subnet-id subnet-08101fac2b2a63a49
#aws ec2 associate-route-table --route-table-id rtb-06928448f0a014e32 --subnet-id subnet-057a3aca47b2b74c9

No comments:

Post a Comment