AWS CLI TASK

Sarthak Agarwal
4 min readNov 12, 2020

Task Description - AWS 👨🏻‍💻

🔅 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.

Firstly we need to set up the CLI interface in windows,for that we need to download latest version of aws cli (v2).

Link for downloading : —

https://awscli.amazonaws.com/AWSCLIV2-2.0.30.msi

After the successful completion of this part we have to open our AWS management console from the browser.

After opening up the console we have to go to IAM user as : —

Then we have to create IAM user as : —

Coming on to our step 1 we have to give the username to the IAM user and in access type we have to give the programmatic access so that we can get the access key ID and secret access key as : —

In step 2 we have to add the user and create a group as : —

Then we have to give the various policies or permissions to the IAM user that he will be able to control by the user ID.There are few policies listed below in the picture : —

Coming on to the step 3,we have to provide the key name in the tags section as : —

Then we have to simply click on create user to add a new IAM user

Coming on to the last step,we have to copy the access key ID and secret access key as : —

Our console part for creating a IAM user is completed.

Now we have to open command prompt from windows and run aws configure command and then we have to paste the access key ID and secret access key in the given part : —

To create new ssh key pair

we can use the syntax : —

aws ec2 create-key-pair -- key-name (yourkeyname) --query’(description of your key or its name)’ > (yourkeyname.pem)

Command entered is shown below : —

Creating a Security Group

To create the security group we have to use the syntax : -

1)aws ec2 create-security-group --group-name (your security group name) --description “(security group description)”

2)aws ec2 authorize-security-group-ingress --group-id (your security group id) --protocol (n/w protocol name) --port (port number) --cidr (custom IP)

how you have to do is shown below : —

To launch the instance using key pair and security group

To launch or run the instance we have to provide security group, instance type,image ID,key name,subnet ID,count and tags.

Syntax :

aws ec2 run-instances --security-group-id (sg ID) -- instance-type (t2.micro (for free)) --image-id (image name) --key-name (ssh key name) --subnet-id (subnet ID ) --count (number of instance) --tag-specifications “ResourceType=instance,Tags=[{Key=Name,Value=(name of instance)}]”

Compilation is shown below : —

Create an EBS volume and attach it to the EC2 instance you created.

1)To create EBS volume we have to follow the syntax :

aws ec2 create-volume --volume-type (SSD type (gp2)) --size (size of volume you want to give) --availability-zone (AZ’s where your instance is running)

2)To attach the volume to the EC2 instance,the syntax is :

aws ec2 attach-volume --device (/dev/the directory of your partition)) --instance-id (instance ID) --volume-id(the volume ID you got from output of step 1)

The compilation of code is shown below :

Finally,the AWS CLI task given by Vimal Daga sir is completed successfully.

Hope it will help you.

Thank you 🙏

--

--

Sarthak Agarwal

Cloud & DevOps Enthusiast ★ARTH Learner ★ AWS ★ GCP ★ Jenkins ★ K8S ★ Ansible ★ MLOps ★ Terraform ★ Networking ★ Python