Using AWS CLI, Launch AWS instance and attach EBS Volume

In this article, let’s deep dive into AWS CLI or Command Line Interface

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

You 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 copythe 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 web UI .

Creating Security group …

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

check using AWS web UI.

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 web UI .

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 for this article. If you find this useful please clap it.

Thanks for reading !!!

#AWSCSA #Arth #VimalDaga #Technologies#Awscloud #Awscli #AWS#Righteducation #Educationredefine #Rightmentor #Worldrecordholder #Linuxworld #MakingIndiaFutureReady #Righteducation #Arthbylw #AWSbyLW#Task3

Lifelong learning technologies

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store