AWS CSA: Creating Key Pair, Security Group , EBS Volume and Attach them to AWS Instance using AWS-CLI?
(AWS CLI में Key Pair, Security Group, EBS Volume बनाना और उसे AWS Instance से संयोजित करना!)

First of all, We have to Download and Install AWS in our system(win/linux/mac) from official amazon aws site and configure:

Now, open your system command prompt and check if it’s installed right or not with:
#aws <space>— version
Now we need to configure the aws in our system with command:
#aws configure
This command will ask you for 4 things:
- Access Key ID(Given by AWS at IAM )
- Secret Key ID(Given by AWS at IAM)
- Region Name(which you are using like “ap-south-1")
- Output Name(style of output like JSON,YML etc)

You can check the Access Key ID and Secret Access Key while creating IAM user and giving it Programmatic Access:

Now we have all access to the AWS account(according to permit in IAM permissions), Keep Your Private Key Secure or Anyone can access your account using that.
So, We will start our task :
1. Create a Key Pair(with AWS CLI)-
It’s really easy when you use AWS CLI, you can create Key Pair with command:
#aws ec2 create-key-pair — key-name <abc>

2. Create a Security Group(with AWS CLI)
Now, we have to give some constraints and permissions to the AWS Instance(It’s like setting up firewall rules for instance):
#aws ec2 create-security-group — group-name <abc> — description “<xyz>” — vpc-id <instance vpc id>

You can check your VPC ID in details of your created instance in AWS Console.
3. Launch an Instance(With AWS CLI)
We can launch a complete instance from CLI But for this we will need some information from AWS as:
- AMI ID: With which OS image, You want to launch.
- Instance Type: For Different Configurations(like t2.micro, t3a.nano etc)
- Count: Number of Instances (Helpful when you need to create multiple instances of same type)
- Subnet ID: It’s not exactly subnet in AWS but we can find it according to Availability zone.
- Security Group ID: It’s like a Firewall or Security/Network Constraints for Instance. You can create(As 2nd Point) or Use already created.
- Key Name: It’s like a key file for authentication when accessing the instance. You can create(As 1st Point) or use already created.
Command for launching an instance is big, but you need not to remember it, as it follows a norm:
#aws ec2 run-instances — image-id <AMI ID of OS> — instance-type <t2.micro> — count <1> — subnet-id <Subnet ID of AZ> — security-group-ids <SG ID> — key-name <kruzes1>

4. Create an EBS Volume of 1 GB(With AWS CLI):
We can think of it as External Storage of Instance, Like Pen Drive in Physical World. In this Cloud World, We can create this storage, Attach and detach it to any instance, It can be used to transfer files between multiple instances.
To create this, We will need:
- Volume type(Type of Volume you want)
- Size (Size of Storage)
- Availability Zone(in which you want to create)
#aws ec2 create-volume — volume-type <gp2> — size <1> — availability-zone <ap-south-1a>
With this command, 1GB of EBS Volume is created in Mumbai South 1a Data-center.

5. Attach the EBS Volume(created) with the created Instance(With AWS CLI):
Now we will attach our EBS Volume of 1 GB with just created instance.
For this, We will need:
- Volume ID(ID of EBS Volume created)
- Instance ID(ID of instance with which we want it to connect)
- Device (Where we want it to share the storage)
#aws ec2 attach-volume — volume-id <> — instance-id <> — device </dev/abc>
with this command, Your storage get connect with the Instance.

The storage is connected with the desired instance, To show it clearly, I am also attaching one screenshot of GUI. So that we can cross check(For Beginners).

Hence, We can clearly check with GUI(Graphical User Interface) also, as we proceed further. This is better way to practice.
Thank You so much for your Valuable time and read, I hope you learned something from this, Please give your feedback or ask your doubts in comment section.
You can also connect with me at:
JAI HIND!