Automation in AWS |CLI | TASK-3 | AWS-CSA | ARTH

Gaurav Sharma
5 min readOct 14, 2020

--

Hey Guys !!!

So in Technical world Automation is necessary, it require minimum human assistance. In manual we need to do every thing by ourself.

As we know for launching an AWS Instance we have to pass 7 pages and have to do lot of clicks, it takes more time & in technical world we don’t much time. But in CLI same thing we can do in one command & one enter.

In AWS we have ways to login into their services:-
1.WebUI: Manual

2.CLI: Automation

3.SDK i.e. Using some programming language.

In techincal world we use WebUI but we can’t do much thing using WebUI so we use CLI coz it provide more features than WebUI.

One more thing, In WebUI if some process fail we can’t the reason why it fail. But CLI have ability to find the reason of this error & we can also Troubleshoot the error.

Pre-requisite

So before doing anything we have download & install AWS command in our PC. Link to download AWS command is given below:-

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

So we have downloaded & installed AWS command Now can move login part. So login we need Access Key & Secret Key and to get these key first we have to create an IAM user.

Here i created IAM user, in step-1 Access type we have to click on Programmatic Access.

We can extract our Access key & Secret key in Step-4. We can also download a text file with Access key & Secret key.

Login:- To login use the below commands:-

aws configure
access key
secret key
region name
output format

After pre-requisites let move to task.

Task discription :-

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.

So lets start the practical part.

Step1 : To Create a key pair I use given command

aws ec2 create-key-pair --key-name gsarth123
Screenshot of CLI
Screenshot of WebUI

We can see in WebUI that a key-pair with name gsarth123 is created.

Step2 : To Create a security group I used the given command

aws ec2 create-security-group --group-name artht3sg --description arth-task-3
Screenshot of CLI
Screenshot of WebUI

Here we can see a Security group with name artht3sg is created.

Step3 : Before launching the instance we need to the security group ids, we can use the given command for this

aws ec2 describe-security-groups

To Launch an instance the command I used is

aws ec2 run-instances --image-id ami-0e306788ff2473ccb --count 1 --instance-type t2.small --key-name "gsarth123" --security-group-ids sg-003e74d493c63ce43 --subnet-id subnet-5cdae034 --tag-specifications ResourceType=instance,Tags=[{Key=Name,Value=arth-OS}]
Screenshot of CLI
Screenshot of WebUI

We can also see in WebUI an OS with arth-OS name.

Screenshot of WebUI
Screenshot of WebUI

Here we can see the attached Key-pair & Security Group which we have created in previous step.

Step4 : To Create an EBS volume of 1 GB the command I use is

aws ec2 create-volume --availability-zone ap-south-1a --size 1 --tag-specifications ResourceType=volume,Tags=[{Key=Name,Value=arth-vol}]
Screenshot of CLI
Screenshot of WebUI

We can also confirm tthrough WebUI a Volume with name art-vol of size 1 GB.

Step6 : To attach the above created EBS volume to the instance command I used is

aws ec2 attach-volume --device /dev/sdf --instance-id i-0ff1b606843c1cdb1 --volume-id vol-0f2ed9c6b3abc9108

We can find Volume ID & Instance ID using given command

aws ec2 describe-instances
aws ec2 describe-volumes
Screenshot of CLI
Screenshot of WebUI

Here we can that our volume arth-vol is attached to our instace arth-OS which we have created in previous steps.

So, finally all steps of the Task is completed.

““““““Thanks For Reading the Blog””””

--

--