To create a subnet inside a VPC using AWS CLI you can use the following command:-
Pre-requisite:-
- AWS CLI configured
- VPC ID
The command used is as follows:-
C:\Users\priyj_kumar>aws ec2 create-subnet --vpc-id vpc-0aca683c37231c12f --cidr-block 10.0.1.0/24
The output you will get after executing the command will be as follows:-
{
"Subnet": {
"AvailabilityZone": "us-east-1e",
"AvailableIpAddressCount": 251,
"CidrBlock": "10.0.1.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "pending",
"SubnetId": "subnet-08f4ee13b627d22bb",
"VpcId": "vpc-0aca683c37231c12f",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": []
}
}
This way you can create a subnet inside a VPC. Hope this helps.