Create VPC Network

Create VPC Network Using AWS CLI From Windows CMD

Tired of AWS GUI dashboard? I want some skills on the CLI command. So, let’s play with AWS CLI. I have already configured AWS CLI on the windows machine. In this article, we will cover VPC, subnets, and Internet gateway. We can create and delete the subnet using AWS CLI. We can also create an internet gateway using AWS CLI. Let’s create a VPC network using AWS CLI.

Create VPC Network Using CLI:

I’m gonna create a VPC network using AWS command with network The below command will create the VPC network.

Check Out: Learn Cat Commands With Examples On CentOS 8

C:\Users\pankaj>aws ec2 create-vpc –cidr-block

Verify on AWS Cloud.

The above command will create the network without giving any name to the network. Now give it a name to recognize the Network The name is MyVPC.

C:\Users\pankaj>aws ec2 create-tags –tags Key=Name,Value=MyVPC –resources vpc-07e8da39a9752db43

We’ve successfully created a VPC network and assigned a name to it. You can also perform the above task using the single line as shown below.

aws ec2 create-vpc –cidr-block –output text | awk ‘{print $NF}’ | xargs aws ec2 create-tags –tags Key=Name,Value=MyVPC –resources

Check Out: How To Install Deluge Bit Torrent Client on Ubuntu 20.04

Delete the VPC Network:

If you want to delete the VPC network using the command line, you can do this with a single command.

C:\Users\pankaj>aws ec2 delete-vpc –vpc-id vpc-07e8da39a9752db43

Create subnets in existing VPC Network:

Once you created a subnet, you can’t change its CIDR blocks.  you can’t change subnet in AWS. 

Note: AWS reserves both the 1st four and last four IPV4 addresses in each subnets CIDR blocks because they’re not available for use.

I will create the subnets in US EAST(N.Virginia). you can choose your availability zone name.

C:\Users\pankaj>aws ec2 create-subnet –vpc-id vpc-07e8da39a9752db43 –cidr-block –availability-zone us-east-1a

Create VPC Network Using AWS CLI

Check Out: Error Elasticsearch Bootstrap Check Failed In Linux

Verify on AWS

vpc network aws cli

Similarly, you can give it a name using the below command.

C:\Users\pankaj>aws ec2 create-tags –tags Key=Name,Value=public-1a –resources subnet-05a79c2db2121347c

We’ve successfully created a VPC and Subnets network using the CLI.

Delete subnets:

You can simply delete the subnets with single commands.

C:\Users\pankaj>aws ec2 delete-subnet –subnet-id subnet-05a79c2db2121347c

Check Out: How To Install Plugins on WordPress 5.4 On Linux 8

Create an Internet Gateway:

If you launch the EC2 instances using the VPC and Subnets which we have created then you won’t be able to access the internet until you don’t create and attach it.

C:\Users\pankaj>aws ec2 create-internet-gateway

 aws cli internet gateway

Now give it a name

C:\Users\pankaj>aws ec2 create-tags –tags Key=Name,Value=MyGW –resources igw-0169d787703fb3e81

Verify on AWS

create subnet aws cli

Attach it using the below command

C:\Users\pankaj>aws ec2 attach-internet-gateway –internet-gateway-id igw-0169d787703fb3e81 –vpc-id vpc-07e8da39a9752db43

Check on AWS

delete subnet in aws cli

If you want to delete it, first you have to detach it then you can remove it. We can also detach using the CLI command.

Check Out: EFS Mount Issue “Failed To Resolve Server: Name or Service Not Known”

C:\Users\pankaj>aws ec2 detach-internet-gateway –internet-gateway-id igw-0169d787703fb3e81 –vpc-id vpc-07e8da39a9752db43

You can also delete it using the single command as shown below.

C:\Users\pankaj>aws ec2 delete-internet-gateway –internet-gateway-id igw-0169d787703fb3e81

You’re done Aws cli internet gateway delete subnet create in


Please enter your comment!
Please enter your name here