Task-3 AWS CLI

Task-3 AWS CLI

What is AWS CLI?

The AWS Command Line Interface (CLI) is a unified tool to manage our AWS services. With just one tool to download and configure, we can control multiple AWS services from the command line and automate them through scripts.

How to run our AWS services through CLI?

Step1 :- First, download and install a software named AWSCLIV2 from internet on your Windows OS.

Step2 :- Set the path of the file during installation and after installing click on Finish

Step3:- Open command prompt and write the command aws --version to check whether the software was installed properly or not. This message gives the confirmation of proper installation.

No alt text provided for this image

Problem Statement

🔅 Create a key pair 

🔅 Create a security group 

🔅 Launch an instance using the above created key pair and security group.

🔅 Create an EBS volume of 1 GB.

🔅 The final step is to attach the above created EBS volume to the instance you created in the previous steps.

All the above steps must be performed using AWS CLI

Step Wise Solution Statements

Step 1 :- Open Command Prompt. We have to configure the IAM user through which we wish to login. To do this write the command aws configure as shown and provide the access key, secret access key , region and output format for the same.

No alt text provided for this image

Step 2:- Create a Key Pair using the command : aws ec2 create-key-pair --key-name piratekey . The key pair would be created as shown

No alt text provided for this image

We can confirm the same from AWS management console as shown

No alt text provided for this image

Step 3:- Creating a Security group

Security Groups allow you to define groups of users with particular access rights defined by the roles attached to the group

We can know how to create a security group by aws ec2 help command , as a security group comes under ec2 category, then we can find the create-security-group command in it . After that write the aws ec2 create-security-group help command to know more about creating an instance in CLI. Then, we will find certain details of a security group that are:-

--description , --groupname and --vpcid

We need to specify their values and hence our security group would be formed by the below command:-

aws ec2 create-security-group --description "pirate-security-group" --group-name piratetask --vpc-id vpc-2353b148

No alt text provided for this image

We can confirm the creation by heading towards AWS Management Console

No alt text provided for this image
No alt text provided for this image

Security Group created.

Step 4:- Next step is to Launch an Instance using the above key pair and security group.

To know how to launch an instance we can use the aws ec2 run-instances help command.

The details needed for launching an ec2 instance are:- --image-id, --instance-type , --count , --security-group-ids , --key-name, --subnet-id

When we give their values along with the aws ec2 run-instances command, then we can successfully launch an instance in AWS through CLI

So, to launch the instance write the below command in the command prompt:-

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --count 1 --security-group-ids sg-06fac79b02c0d42fd --key-name piratekey --subnet-id subnet-f4f2f99c

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

We can confirm that an instance has launched, from the AWS Management Console as:-

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

The Instance has been launched successfully.

Step 5:- Now we have to Create an EBS Volume.

To know how to create an EBS volume we can use the command aws ec2 help and through it we can find the details needed for creating an EBS volume, and that are:- --availability-zone , --size

Therefore, by writing the below command, we can successfully create an EBS volume of size 1GB

aws ec2 create-volume --availability-zone ap-south-1a --size 1

No alt text provided for this image

We can confirm the same from the AWS Management Console as below:-

No alt text provided for this image

EBS volume created successfully.

Step 6:- Now our task is to attach the above created EBS volume to the instance that we created earlier through AWS CLI

To attach the EBS volume first we need to know its details, which can be found out through aws ec2 help command in the command prompt, and that are:- --instance-id , --volume-id , --device

Hence, by giving the values of the above attributes we can attach the created EBS volume to our created instance in AWS CLI . The command for the same is given below:-

aws ec2 attach-volume --instance-id i-0844758151a306a0e --volume-id vol-016b0053dd65f3dd8 --device /dev/sdh

No alt text provided for this image

We can verify that the EBS volume is attached or not, from the AWS Management Console as:-

No alt text provided for this image

The EBS volume is attached to the instance successfully.

***************************TASK COMPLETE******************************

THANK YOU FOR READING



To view or add a comment, sign in

More articles by Geetansh Sharma

Others also viewed

Explore content categories