Intro to AWS CLI

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.

Note : You can download it as per OS : https://aws.amazon.com/cli/

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

Command :

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

Next, configuration using AWS Access Key, AWS Secret Access Key, Region Name and Output Format is performed

Command :

aws configure
AWS Configuration

Creation of Key Pair

Command :

aws ec2 create-key-pair  --key-name task_3

Creates an EC2 Key Pair named task_3.

Creation of EC2 Key Pair

Creation of Security Group

Part 1 : Creation of Security Group

Command :

aws ec2 create-security-group  --description "Task 3 Security Group"     --group-name task3_sg

Create a Security Group named task3_sg.

Creation of EC2 Security Group

Part 2 : Addition of Ingress Rule

Command :

aws ec2 authorize-security-group-ingress  --group-name task3_sg   --protocol tcp   --port 22    --cidr 106.209.209.54/32

Creates an Ingress/Inbound rule and allows traffic via SSH only (TCP Port 22) and from a specified CIDR only.

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}]

Creates an EC2 Instance using Image, Instance Type, Subnet , Security Group, Key and Tag specified.

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

Creates an EBS Volume in the availability zone “ap-south-1a” and of size 1 GiB.

Note: The EBS Volume should be created in the same availability zone as of the EC2 Instance to which it would be attached as EBS is a Zonal Service.

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

Attaches the EBS Volume of ID specified to the EC2 Instance whose ID is specified (Both of them should be in same availability zone).

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”

--

--

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