Using AWS CLI, Launch AWS instance and attach EBS Volume …

Nithish Kumar
4 min readOct 18, 2020

… Click by NKumar …

In this article, I wanna introduce the AWS CLI,.. Join along with me and explore the AWS Services using AWS CLI …

Prerequisites :

📌 Install the CLI Software of AWS in Linux,..

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" 
$ unzip awscliv2.zip
$ sudo ./aws/install

You can go through the website for more detail… Click HERE

📌 After installing software, check

$ aws --version

U will see similar output …

📌 Now configure the aws in your system … For this, you need to create IAM user in your AWS account … First login to your account, And go to IAM Service. Now create a new user by clicking on “ Add User ”

Download the credentials file into your system,..

📌 Now run the below command :

$ aws configure

Now copy the access key ID and secret access key from credentials file which u have downloaded and paste one by one into console output …

Creating Key-Pair …

$ aws ec2 create-key-pair — key-name cli-key — output text > cli-key.pem

U can also check using AWS webUI . 👇

Creating Security group …

$ aws ec2 create-security-group --group-name task-cli --description allow-ssh-icmp

check using AWS webUI . 👇

Now create rules which allows “SSH” and “ICMP”

$ aws ec2 authorize-security-group-ingress — group-name task-cli — protocol icmp — port -1 — cidr 0.0.0.0/0$ aws ec2 authorize-security-group-ingress — group-name task-cli — protocol tcp— port 22— cidr 0.0.0.0/0

check using AWS webUI . 👇

Launching new instance…

$ aws ec2 run-instances \
> --instance-type <instance-type> \ # ex: t2.micro
> --image-id <image-id> \ # ex: ami-0e306788ff2473ccb
> --count 1 \
> --security-groups <name of the SG>\ # ex: task-cli
> --key-name <your key-name> # ex: cli-key

check using AWS webUI . 👇

Creating EBS Volume…

$ aws ec2 create-volume \
> --volume-type gp2 \
> --size 1 \
> --availability-zone ap-south-1a

U will see the volume with available state . 👇

Attaching EBS Volume

Now attach this EBS volume to the instance which we have created before,..

$ aws ec2 attach-volume \
> --volume-id <volume-id> \ # ex: vol-0e035469e737e8761
> --instance-id <instance-id> \ # ex: i-015c98656881da46b
> --device /dev/xvdh

U will see the EBS volume is attached to the instance . 👇

🙌 That’s all Folks,…
👋 See U in the next article,…

🤝 Thanks for reading !!! 🤝

…. Signing Off ….

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Nithish Kumar
Nithish Kumar

Written by Nithish Kumar

Aspiring DevOps/Cloud Engineer. #Believe in you.

No responses yet

Write a response