How Launch/Create AWS Instances using AWS CLI

Muskan Agarwala
3 min readJul 8, 2021

What is AWS Cloud?

Amazon web service is a platform that offers flexible, reliable, scalable, easy-to-use and cost-effective cloud computing solutions.

AWS is a comprehensive, easy to use computing platform offered Amazon. The platform is developed with a combination of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings.

What is AWS CLI?

It is basically a way of operating the AWS Services. With the help of CLI you can configure & control Multiple AWS services at the same time.

Pre-Requisite: One should have AWS CLI software installed in their system.

Install AWS CLI software and add it’s path to environment variable.

Now, we are ready to go!!

STEP:1

To check AWS CLI software is working or not.

aws

STEP:2 (Login)

aws configure

But it’s asking for some Access Key & Secret Key. What it is…😶. Don’t worry it’s just like a username/password asking before login. So create it first, for this create one IAM user. When you create it successfully you will get an access key(username) & secret key (password). Choose any region name as you wish.

STEP:3 (create a New Key Pair)

aws ec2 create-key-pair — key-name <key_name>

STEP:4 (Create security group)

aws ec2 create-security-group — group-name <value> — description “<value>”

STEP:5 (launch a new instance using above key-pair & security group)

aws ec2 run-instances — image-id <value> — instance-type <value> — count <value> — subnet-id <value> — key-name <value> — security-group-ids <value>

Now our instances is successfully launched😀.

STEP:6 (create EBS volume)

aws ec2 create-volume — volume-type gp2 — size 1 — availability-zone ap-south-1a

STEP:7(attach EBS volume to the instance)

aws ec2 attach-volume — instance-id <value>— volume-id <value>— device /dev/xvdf

Now in next steps we are going to detach the EBS volume & then finally terminate the instance.

Note: must detach EBS volume first before terminating the Instance.

STEP:1 (detach the EBS volume)

aws ec2 detach-volume — volume-id <value>

STEP:2 (terminate the Instance)

aws ec2 terminate-instances — instance-ids <value>

Now we are all done!!!!✨

--

--