Why AWS CLI?

The AWS Command Line Interface (CLI) is a unified tool that manages the AWS services for you.

1.) Create a key pair
2.) Create a security group
3.) Launch an instance using the above created key pair and security group.
4.) Create an EBS volume of 2 GB.
5.) The final step is to attach the above created EBS volume to the instance you created in the previous steps.

Using aws help command, we can create our customized commands

Step 1: Create an IAM user through your AWS account and give programmatic access

Step 2: Configure aws

Configure AWS using the command aws configure .Enter AWS Access key, Secret key, default region name and default output format

Step 3: Create a key pair

The following command creates a 2048-bit RSA key pair with the specified name.

aws ec2 create-key-pair  --key-name <value>
In AWS GUI you can see that a key pair has been created

Step 4: Create a security group:

A security group acts as a virtual firewall for your instance to
control inbound and outbound traffic.

aws ec2 create-security-group  --group-name <value> --description <value>
i
Through AWS GUI, we can confirm the created security group

Step 5: Authorize security group

Add the specified ingress rules to a security group. An inbound rule permits instances to receive traffic from the specified IPv4 or IPv6 CIDR address ranges, or from the instances associated with the specified destination security groups

aws ec2 authorize-security-group-ingress --group-id <value> --protocol <value> --port <value> --cidr <value>
The following command enables inbound traffic on TCP port 22 (SSH)
We can confirm here that the inbound rules has been specified

Step 6 : Launch an instance

Launch the specified number of instances using an AMI .

aws ec2 run-instances --image-id <value> --instance-type <value> --key-name <value> --subnet-id <value> --count <value> --security-group-ids <value> --tag-specifications <value>
We can see here that an instance has been created

Step 7: Create an EBS volume

Create an EBS volume that can be attached to an instance in the same
Availability Zone.

aws ec2 create-volume  --availability-zone <value> --size <value>
Through GUI, we can confirm that an EBS volume has been created

Step 8: Attach the above created EBS volume to the instance you created in the previous steps.

Attaches an EBS volume to a running or stopped instance.

aws ec2 attach-volume --device <value>  --instance-id <value>  --volume-id <value>