The basic concept of a subnet in AWS is the same as in on-premise environments. Namely it is a network within a network. Separate subnets can be defined to create a logical or physical boundary between components. Unique AWS-specific concepts are as follows:
- If a system is deployed across different Availability Zones (different datacenters), a separate subnet must be defined for each Availability Zone.
- If instances within a subnet need direct access from/to the Internet, it should be configured as a “public” subnet. Note that if instances need to be separated from/to the Internet, it should be configured as a “private” subnet. Consequently, there may need to be more than 2 subnets defined per Availability Zone.
Refer to the AWS documentation for more information.
In this tutorial, we will use three (3) Availability Zones and use only the “public” pattern to simplify the process. A “public” subnet is created as follows:
- Go to the Subnet page by selecting “Subnets” from the navigation pane at the left side.
- As per the VPC, there are pre-defined subnets for the default VPC. Select “Create Subnet” from the top right corner.
- Specify following parameters as shown in the screenshot:
- VPC ID: LK-VPC
- Subnet Name: LK-subnet-1
- Availability Zone: Select the first option.
- IPv4 CIDR block: 10.20.1.0/24
- Tag: Name = LK-subnet-1
While working in this wizard, a list of Availability Zones can be seen by selecting the dropdown box for the Availability Zones:
Select the first Availability Zone (in this case us-west-2a)
- Now the first subnet on Availability Zone us-west-2a is created. Return to the “Subnet Page”.
- Create the second subnet LK-subnet-2 with CIDR block 10.20.2.0/24 in another Availability Zone us-west-2b.
- Create the third subnet LK-subnet-3 with a CIDR block 10.20.3.0/24 on the Availability Zone us-west-2c.
- Once the three subnets have been created, the list of subnets should be as shown in the screenshot below. The first subnets in the picture are the “default“ subnets created for “default” VPC followed by the three subnets we have just created.
- In this tutorial we will create a public subnet. This signifies that we want to assign a public IP address for instances we create under this subnet. To do so, select the subnet we have just created and then select “Modify auto-assign IP settings” from the Actions menu.
- Select “Enable auto-assign public IPv4 address”, and save the change.
- Now the subnets are ready to use.