What is AWS CLI ?

The AWS Command Line Interface (CLI) is a unified tool for managing AWS services. With just one tool to download and configure, it enables controlling multiple AWS services from the command line and their automation through scripts.

Content of this Blog

  • Creation of Key Pair
  • Creation of Security Group
  • Creation of EC2 Instance using the Key Pair and Security Group created
  • Creation of EBS Volume
  • Attachment of EBS Volume created to the EC2 Instance created

Prerequisites

First, check if AWS CLI has been successfully installed or not

aws --version
It indicates that AWS CLI has been installed successfully
aws configure
AWS Configuration

Creation of Key Pair

Command :

aws ec2 create-key-pair  --key-name task_3
Creation of EC2 Key Pair

Creation of Security Group

Part 1 : Creation of Security Group

aws ec2 create-security-group  --description "Task 3 Security Group"     --group-name task3_sg
Creation of EC2 Security Group
aws ec2 authorize-security-group-ingress  --group-name task3_sg   --protocol tcp   --port 22    --cidr 106.209.209.54/32
Security Group created in AWS Web Console

Creation of EC2 Instance using the Key Pair and Security Group created

Command :

aws ec2 run-instances  --image-id ami-0e306788ff2473ccb    --instance-type t2.micro    --count 1   --subnet-id subnet-057c3dcaa38c9263a    --security-group-ids sg-0936d713fd54b562d  --key-name task_3 --tag-specifications ResourceType=instance,Tags=[{Key=Name,Value=Task_3_Instance}]
Creation of EC2 Instance
AWS EC2 Instance created in AWS Web Console

Creation of EBS Volume

Command :

aws ec2 create-volume --availability-zone ap-south-1a   --size 1
Creation of EBS Volume
The one selected is the EBS Volume created in AWS Web Console, also the State “available” indicates that it hasn’t been attached to an EC2 Instance yet

Attachment of EBS Volume created to the EC2 Instance created

Command :

aws ec2 attach-volume  --device /dev/xvdb  --instance-id i-0a767bee02cce681a  --volume-id vol-006ec918a2a88efbd
Attachment of EBS Volume to EC2 Instance
Attachment of EBS Volume could be observed in EC2 Instance details in AWS Web Console
Changes could be observed in the State of the EBS Volume created previously from “available” to “in use”