Here’s the Table of Contents (TOC) for the provided document:
#aws/cookbook/Networking
When creating a VPC in a Region, it is a best practice to spread subnet across AZs in the networking tier. The number of AZs different per region, but most have at least three. A Subnet has one route table associated with it. Route Tables can be associated with one or more subnets and direct traffic to a destination. Entries within route tables are called routes and are defined as pairs of Destination and Targets. When a route table is created a default local route is added for intra-VPC traffic.
VPC_ID=$(aws ec2 create-vpc --cidr-block 10.10.0.0/23 \
--tag-specifications \
'ResourceType=vpc,Tags=[{Key=Name,Value=AWSCookbook202}]' \
--output text --query Vpc.VpcId)
ROUTE_TABLE_ID=$(aws ec2 create-route-table --vpc-id $VPC_ID \
--tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=AWSCookbookSuryendu202}]' \
--output text --query RouteTable.RouteTableId )
SUBNET_ID_1=$(aws ec2 create-subnet \
--vpc-id $VPC_ID \
--cidr-block 10.10.0.0/24 \
--availability-zone ${AWS_REGION}a \
--tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=AWSCookbookSuryendu202a}]' \
--output text --query Subnet.SubnetId )
SUBNET_ID_2=$(aws ec2 create-subnet \
--vpc-id $VPC_ID \
--cidr-block 10.10.1.0/24 \
--availability-zone ${AWS_REGION}b \
--tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=AWSCookbookSuryendu202b}]' \
--output text --query Subnet.SubnetId )
aws ec2 associate-route-table \
--route-table $ROUTE_TABLE_ID --subnet-id $SUBNET_ID_1
aws ec2 associate-route-table \
--route-table $ROUTE_TABLE_ID --subnet-id $SUBNET_ID_2
{
"AssociationId": "rtbassoc-0c58de60a9584de72",
"AssociationState": {
"State": "associated"
}
}
{
"AssociationId": "rtbassoc-0a7e8c81bae6bd16c",
"AssociationState": {
"State": "associated"
}
}
We can describe each resource to validate deployments.
aws ec2 delete-subnet --subnet-id $SUBNET_ID_1
aws ec2 delete-subnet --subnet-id $SUBNET_ID_2
aws ec2 delete-route-table --route-table-id $ROUTE_TABLE_ID
aws ec2 delete-vpc --vpc-id $VPC_ID
unset VPC_ID
unset ROUTE_TABLE_ID
unset SUBNET_ID_1
unset SUBNET_ID_2