Creating VPC and Subnets

Virtual Private Cloud (VPC) is a Software-Defined Network. You can configure a virtual network on AWS. Subnets are inside of VPC that define network block (Classless Inter Domain Routing (CIDR)) such as 192.168.1.0/24.

Let's create one VPC and two subnets using the following steps:

  1. Create a new VPC that has 192.168.0.0/16 CIDR block (IP range: 192.168.0.0192.168.255.255). Then, capture VpcId:
$ aws ec2 create-vpc --cidr-block 192.168.0.0/16
{
"Vpc": {
"CidrBlock": "192.168.0.0/16",
"DhcpOptionsId": "dopt-3d901958",
"State": "pending",
"VpcId": "vpc-69cfbd12",
"InstanceTenancy": "default",
"Ipv6CidrBlockAssociationSet": [],
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-c35411ae",
"CidrBlock": "192.168.0.0/16",
"CidrBlockState": {
"State": "associated"
}
}
],
"IsDefault": false,
"Tags": []
}
}
  1. Create the first subnet under the VPC (vpc-69cfbd12) that has 192.168.0.0/24 CIDR block (IP range: 192.168.0.0192.168.0.255) and specify the availability zone as us-east-1a. Then, capture SubnetId:
$ aws ec2 create-subnet --vpc-id vpc-69cfbd12 --cidr-block 192.168.0.0/24 --availability-zone us-east-1a
{
"Subnet": {
"AvailabilityZone": "us-east-1a",
"AvailableIpAddressCount": 251,
"CidrBlock": "192.168.0.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "pending",
"SubnetId": "subnet-6296863f",
"VpcId": "vpc-69cfbd12",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": []
}
}
  1. Create the second subnet on us-east-1b, which has 192.168.1.0/24 CIDR block (IP range: 192.168.1.0192.168.1.255). Then, capture SubnetId:
$ aws ec2 create-subnet --vpc-id vpc-69cfbd12 --cidr-block 192.168.1.0/24 --availability-zone us-east-1b
{
"Subnet": {
"AvailabilityZone": "us-east-1b",
"AvailableIpAddressCount": 251,
"CidrBlock": "192.168.1.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "pending",
"SubnetId": "subnet-ce947da9",
"VpcId": "vpc-69cfbd12",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": []
}
}
  1. Check the subnet list under VPC (vpc-69cfbd12) using the following command:
$ aws ec2 describe-subnets --filters "Name=vpc-id,Values=vpc-69cfbd12" --query "Subnets[*].{Vpc:VpcId,CIDR:CidrBlock,AZ:AvailabilityZone,Id:SubnetId}" --output=table
---------------------------------------------------------------------
| DescribeSubnets |
+------------+------------------+-------------------+---------------+
| AZ | CIDR | Id | Vpc |
+------------+------------------+-------------------+---------------+
| us-east-1a| 192.168.0.0/24 | subnet-6296863f | vpc-69cfbd12 |
| us-east-1b| 192.168.1.0/24 | subnet-ce947da9 | vpc-69cfbd12 |
+------------+------------------+-------------------+---------------+

This looks good!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.218.5