Instance launched & Attached EBS volume using AWS CLI
The steps is likewise:
1. Create a Key-pair
2. Create a Security-group
3. Launched a instance using the above created key-pair & security group.
4. Now create a EBS volume of 1 GB
5. Finally attached that EBS volume with above launched instance
So now we will go step by step
If you haven’t aws-cli installed use this command to install the aws-cli
Windows:- msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
aws — version
Linux:- curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o “awscliv2.zip”
unzip awscliv2.zip
sudo ./aws/install
After installation complete run the command that is
“ aws configure”
put the access key, secret key & region.
1. We are creating the key-pair by aws-cli using some commands & giving a proper name of that key-pair
After using this command if you will go to your AWS dashboard you will see key-pair is created,below image for your refrence
2. Now we are creating Security -group using aws-cli,for which we will used some command & also put the name of security group which you want
Now if you will go to your aws-dashboard & you will see security group created by your reference with the same name
3. Now time to launch the instance with same security group and key-pair but in the command one more thing need to put that is AMI-id or image-id because of you know if you need any OS, every OS has some iso file. OS is what !! OS is collections of multiple files or program where you performed your own program, So Amazon has lots of different-different types of image for different different OS likewise Ubuntu, Centos, RHEL, Amazon Linux etc.
So now we will put the commands in command line. First give the ami-id then how many instance you wants to launched that is count, instance-type that is t2.micro(AWS has different-different types of instance, instance types based on the CPU or RAM. T2.micro is free there is no charged for this so that’s why i used t2.micro gives us 1CPU or 1GB RAM.),after that put the key-pair name and security-group ids.
Now you will go to ec2-Dashboard you will see instance is launched with same key-pair or same security group.
with same key-pair
with same security-group
4. Now we will create EBS Volume with some specific size that is 1GB but here you need to do one thing more that is if you wants to connect that EBS volume with any instance that instance should be in same region also in the AZ(Availability zone). Every region has two AZ that is a or b,so my instance is launched in mumbai-region(ap-south-1) and the az is ap-south-1a so we need to create EBS volume in same AZ.
So for creating EBS volume you need to put at least three things volume-type. volume size & Availability zone.
Now if you will go to dashboard you will see EBS Volume launched with a size of 1GB in ap-south-1a availability zone.
5. Now we will go for the final step that volume attachment with the launched instance. In the above picture you will see the Volume state is showing available but as soon as we run the command volume is attached with that instance & state is changed. For attaching the volume we need to put two things first one is that the volume-id and second one is the instance-id. Also give the device name otherwise it will automatically collect.
Now if you will go to Volume dashboard you will see volume state is changed and it is showing in-use. Also if you will go to instance dashboard in the storage frame you will see two disk they have one root volume & other one is EBS volume.
That’s it your task is completed.
I have done these things by run the command one by one but you can use file now a days for this infrastructure a advanced tool is used that is Terraform, you can perform all of these things in one go & it will create within 10–15 second. I will also write blog on this in upcoming days.
Thank You🤩