AWS Tutorial - Create VPC and Launch Instance Using CLI - Skillslane
AWS Tutorial - Create VPC and Launch Instance Using CLI - Skillslane
AWS Tutorial - Create VPC and Launch Instance Using CLI - Skillslane
In this tutorial, i will describe the steps required to create a VPC using AWS CLI.
Prerequisites
1. You need to have a configured AWS CLI on your system. (Refer this tutorial:
Configure AWS CLI)
Create VPC using CLI
https://skillslane.com/aws-tutorial-vpc-launch-instance-cli/ 1/6
1/20/22, 11:43 PM AWS Tutorial: Create VPC and Launch Instance Using CLI | Skillslane
The first step in creating VPC is deciding on the CIDR range. The maximum CIDR
range you can have on AWS is /16 network. In this tutorial, i am going to create a
VPC with CIDR range 10.0.0.0/16. Please note down all the id’s created in a
notepad when you are executing the command.
The above command will give an out with a parameter named.VpcId Note down
the Id because we would need it for further commands.
Note: If you want to learn AWS from scratch for want to prepare for AWS
certificate programs, you can go for Ryan’s Courses on Udemy. You can get these
$197 worth of courses for just $9.99 using coupons from here –> A Cloud Guru
AWS certification Udemy Course Coupons
Next, we need to create subnets for the VPC we created. Subnets basically give
you a segregation for your application. Let’s say you have a front end, app tier,
and Db tier. You might need 6 subnets to host that application in high availability
mode.
For this demo, I will create two subnets, one private and one public.
https://skillslane.com/aws-tutorial-vpc-launch-instance-cli/ 2/6
1/20/22, 11:43 PM AWS Tutorial: Create VPC and Launch Instance Using CLI | Skillslane
Note down the subnet id from the output. We will need it later.
If you want to access ec2 instances over the internet, you should attach an
internet gateway to your VPC.
First,
create a route table. Replace the VPC id with yours.
https://skillslane.com/aws-tutorial-vpc-launch-instance-cli/ 3/6
1/20/22, 11:43 PM AWS Tutorial: Create VPC and Launch Instance Using CLI | Skillslane
Attaching internet gateway does not make all the subnets public. If you want to
make a subnet public, you need to add a route table with internet gateway to the
subnet.
Associate the route table with the second subnet using associate-route-
table command and the ids.
Now our second subnet is a public subnet as we associated a route table with
internet gateway rule. We can now launch an instance to the public subnet which
can be accessed over the internet. If you launch an ec2 instance in the private
subnet (first subnet – 10.0.1.0/24), you will not be able to access it as it does not
have an internet gateway rule. But all the instances in a VPC can talk to each
other using its private IP’s.
There are few parameters you should know before launching the instance.
1. AMI ID: id of the image (OS) that you want to launch.You can get this id from the
AWS launch wizard as shown below.
2. Security Group ID: Create a security group and get the id.
3. Subnet ID
4. Key pair Name – Create a key pair and note down the name.
Execute the following command with relevant ID’s to launch the instance in public
subnet.
SHARE TWEET
https://skillslane.com/aws-tutorial-vpc-launch-instance-cli/ 5/6
1/20/22, 11:43 PM AWS Tutorial: Create VPC and Launch Instance Using CLI | Skillslane
skillslane
The new economy needs a new approach to education. Education is no longer a one-time
investment at the beginning of one's career, it's a lifelong pursuit. We're building an
educational experience that empowers our readers to thrive in this new world order.
Skillslane
©skillslane. All rights reserved.
https://skillslane.com/aws-tutorial-vpc-launch-instance-cli/ 6/6