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
Next, configuration using AWS Access Key, AWS Secret Access Key, Region Name and Output Format is performed
Command :
aws configure
Creation of Key Pair
Command :
aws ec2 create-key-pair --key-name task_3
Creates an EC2 Key Pair named task_3.
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.
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.
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 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.
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).
Thank You !!!
LinkedIn URL : https://www.linkedin.com/in/satyam-singh-95a266182