Creating New Key, Security Group,EBS Volume In AWS Using CLI
So guys in this article you will get to know how to use AWS services using CLI like key-pair, security-groups and EBS-volume. So let’s start
Pre-Requisite — AWS-CLI installed and have been loged-in using Access key and Secret key.
Here is the brief description-
- Creating a key-pair .
- Creating a security group.
- Launch an instance using the above created key-pair and security-group.
- Create an EBS volume of 10GB.
- The final step is to attach the above created EBS volume to the instance you created in the previous steps.
1.Creating a key-pair
As from below image you can see their is only two key presents.
Open terminal and write the command as-
aws ec2 create-key-pair — —key-name any_name (in my case it’s newclikey)
Now check the image below a third key has been added to the list namely as newclikey..
2.Creating a Security Group
Here is the image showing 4 security group already created.
Now for creating new security group write the below command-
aws ec2 create-security-group — — group-name MySecurityGroup — — description “My security group”
Here is the image after running above command-
If you wants to add inbound rule to the security group then after creating security group run the below command-
aws ec2 authorize-security-group-ingress — — group-id sg-05ccf1d08bc78dfee — — protocol all — — port 0 — — cidr 0.0.0.0/0
This command will allow all traffic coming to the instance of any port no and any IP. Here is the image showing output of the command-
3.Launching an Instance using the above created key-pair and Security-Group.
Run the below command to launch an Instance of above created key-pair(newclikey) and security-group(My SecurityGroup)
aws ec2 run-instances — — subnet-id subnet-9eede6f6 — — image-id ami-052c08d70def0ac62 — — instance-type t2.micro — — count 1 — — security-group-ids sg-05ccf1d08bc78dfee — — key-name newclikey
Here we have to give security-group-id in the same option of the the scurity-group.Below is the Image showing EC2-Dashboard after launching instance. You can see the security group and key-pair name are same that I have created in above steps.
4. Create an EBS volume of 10GB.
Now create an EBS volume of 10GB.Write the below command in your command line-
aws ec2 create-volume — — size 10 — no-encrypted — — availability-zone us-east-1a — — tag-specifications ‘ResourceType=volume,Tags=[{Key=Name,Value=myCLIVolume}]
In Bove command volume-type I have given gp2 which means General purpose ssd, availability-zone as ap-south-1a which means in Mumbai a data center, size 10GB and n0-encrypted for no encryption of data storing in this and added a tag called Name and its value as myCLIVolume.
5.The final step is to attach the above created EBS volume to the instance you created in the previous steps.
Below is the image showing before attaching the above created volume to the instance where only one volume is attached which is for instaling os.
Now run the below command to attach the volume-
aws ec2 attach-volume — — instance-id i-02dfccdaa51057cfc — — volume-id vol-0c335db9509a6c922 — — device /dev/sdk
Here All option that i have given is mandatory and we have to give instace-id to which instance we wants to attach and the volume-id of the volume we wants to attach
Here is the image after volume attached-
So guys finally all done successfully created a key-pair, security-group, launched a instance with created key-pair and security-group, created an EBS volume, and atteched the volume to the previously launched instance.
That’s all guys.
Thank you.. Hope this article help you in exploring these things…
Connect me on linkedIn for more updates in technologies