Working with AWS CLI
We’ll be learning how to launch an ec2 instance, creating key pairs, security groups, creating a simple EBS volume and attaching it to the launched ec2 instance.

Let’s get started…
STEP 1: Firstly we need to configure our AWS using the following command.
aws configure
Enter your credentials (access key and secret key), the region you want to work on and the default output format and then press enter.
STEP 2: Now we’ll move on for creating a new key pair through the following command:
aws ec2 create-key-pair --key-name <Key Name>

Save the content of the key pair in a file with an extention of .pem so that it could be used further.

We can also cross check if our process was successful through AWS WebUI.

STEP 3: Creating a security group for attaching in the instance using the following command:
aws ec2 create-security-group --group-name <Security group name> --description <sg description>
The Security group gets created.

Cross checking through the WebUI.

STEP 4: Now we’ll launch an instance wherein we’ll attach the key pair and the security group we just created using the following command:
aws ec2 run-instances --image-id <image id> --instance-type <instance type> --security-groups <security group name> --key-name <key name>
The ec2 instance gets launched after running this command.

Cross checking it through WebUI.

STEP 5: Creating an EBS volume of 1 GB using the following command:
aws ec2 create-volume --size 1 --availability-zone <availability zone>
The EBS volume of 1GB gets created.

Cross checking through WebUI.

STEP 6: Attaching the EBS volume which was just created to the instance through the following command:
aws ec2 attach-volume --volume-id <volume id> --instance-id <instance id> --device /dev/sdf
The EBS gets attached to the created instance.

Cross checking through WebUI.

Summary:
- Created a key pair.
- Created a security group.
- Launched an ec2 instance wherein the created key pair and security group were attached.
- Created an EBS volume of 1 GB.
- Attached the EBS volume to the instance.
