Creating New Key, Security Group,EBS Volume In AWS Using CLI

Pawan Kumar
4 min readOct 14, 2020

--

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-

  1. Creating a key-pair .
  2. Creating a security group.
  3. Launch an instance using the above created key-pair and security-group.
  4. Create an EBS volume of 10GB.
  5. 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.

Before Key Creating

Open terminal and write the command as-

aws ec2 create-key-pair — —key-name any_name (in my case it’s newclikey)

Commnad to create key-pair

Now check the image below a third key has been added to the list namely as newclikey..

Key Created

2.Creating a Security Group

Here is the image showing 4 security group already created.

Before Creating Securtiy-Group

Now for creating new security group write the below command-

aws ec2 create-security-group — — group-name MySecurityGroup — — description “My security group”

Command To Create Security-Group

Here is the image after running above command-

After Security-Group Created

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-

Adding Inbound Rule

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

Launching New Instances

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.

After Launching from CLI

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

Command To Create Volume

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.

Deafualt attached volume only

Now run the below command to attach the volume-

aws ec2 attach-volume — — instance-id i-02dfccdaa51057cfc — — volume-id vol-0c335db9509a6c922 — — device /dev/sdk

Command to Attach Volume

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-

After Volume Attach

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

--

--

No responses yet