Arth-Task-3

Mdkneema
3 min readOct 28, 2020

In this task, we need to do the following using cli-

1. Creating the key pair-

To create the key pair, we use the command- aws ec2 create-key-pair — keyname new_key_pair_demo_cli.

But we need to store the private key to use it in creating the instance. for that we need to run the following command- aws ec2 create-key-pair — key-name new_key_pair_demo_cli > new_key_pair_demo_cli.pem. this command stores the private key into the file- new_key_pair_demo_cli.pem.

by running the above command, we get the private key but our objective is to only acquire the KeyMaterial but in the above command we get the complete key:values like KeyFingerprint, KeyMaterial, KeyName and KeyPairId. we can either manually edit or run the command- aws ec2 — key-name new_key_pair_demo_cli — query ‘KeyMaterial’ — output text > file.pem. This command will only store the KeyMaterial so that we can use it as private key.

2. Create a security group-

the command that is used to create the security group is aws ec2 create-security-group

we can also add rules to the group (will be done in future).

3. Create AWS Instance using above security group and key pair-

The aws instance will be created by using a single command which will include both key pair and security group created in the above steps. The command os aws ec2 run-instances — image-id ami-0947d2ba12ee1ff75 — instance-type t2.micro — count 1 — subnet-id subnet-e945dba4 — security-groups-ids sg-05c06f9bf2470c65b — key-name new_key_pair_demo_cli

4. Create EBS volume of 1 gb-

The command to create 1gb of ebs volume is- aws ec2 create-volume — size 1 — availability-zone us-east-1c

5. Attach EBS volume to the instance-

The only requirement for this is the ebs volume should be in the same AZ as the instance. The command is aws ec2 attach-volume — device /dev/sdh — instance-id i-03b95954bd0fd95ee — volume-id vol-03877eeba07343382

The EBS Volume is attached and ready to use.

--

--