Getting Started with Amazon Web Services on CLI

The Cloud keeps growing

There are many ways we can use the Amazon Web Services. The most common method being the Web UI found at

This conventional method might be pretty easy to use but it is very slow as all the work has to be done manually. This is because accessing contents of GUI is always slower than the command line interface. The command line is always more powerful than the GUI.

For example let’s say you have to create 15 EC2 instances on AWS , 3 running on Amazon Linux, 7 having RHEL 8 configuration and the rest being Windows. This itself presents a tedious job of clicking and waiting for the WEB UI to respond. But a single command in the CLI gets the job done quicker and is less prone to errors because while accessing the GUI we tend to make more human errors.

In this article we would be setting up an EC2 instance by creating a new key-value pair and security group using CLI. Then we would be attaching an EBS storage to our running instance. All this would be done mostly by accessing the power of the command line interface.

Creating the new key-value pair and security group

For creating the new key-value pair we use

Since the key is created for the ec2 instance we first have to specify the command or the service we want to access. “create-key-pair” is the sub command or one of the features of the ec2 service. “key-name” is the option or property we specify for the feature we are using and “newclikey” is the name of the key being created.

The output is of the form

I have blurred out the values of the key for obvious security reasons.

So we got the new value setup.

Next we have to set up the security group

For that we use the command

The given command creates a new security group by the name of “clisecuritygroup2” , the description option is not mandatory .

Before beginning the EC2 instance setup I would like to remind that all the services and the components of the services that are created are referred to by their ID. This ID is unique to them. The AWS doesn’t refer to the instances by the name we give them but by the unique ID that is assigned to them.

Setting up the new EC2 instance

Once we have the security and the key pair created the next task is to launch a new instance .

The image id specified is the ID of the redhat AMI . This tells AWS to use the redhat OS while launching the system. The count tells that there is just one instance we need to create of the t2.micro. The rest two options are to specify the key-value pair and the security group.

You can check if the instance is activated using the WEB UI too. I will leave that up to you to decide.

Creating the EBS Storage

Next we must create a volume before we attach it to our EC2 instance. For creating the instance we use

Since EBS is a zonal service we have to specify the zone in which we need to create the volume. This creates the volume in “ap-south-1a” which is located in Mumbai. Now we need to attach this volume to the EC2 instance we created before.

The EC2 t2.micro is free-tier eligible so we need not to worry about the billing. The AWS allows 750 hours of t2.micro use every month without incurring any charges.

The following command attaches the volume that we created to the EC2 instance.

This commands take in the parameters volume-id and the instance-id. In addition we specify the device where we mount the volume.

Since our task is done which we initially planned we can have a look at the WEB UI to see if the volume was not attached to the EC2 instance.

The 10 GB volume is of the EC2 instance and 1GB of the volume that we attached. Be careful you check through the same account you signed in from the CLI on the WEB UI too.

Before concluding I would like to add that when beginning to use the CLI we often are overwhelmed by the amount of commands that are available at our disposal. For this the help is available which can be used against any service to see it’s use or parameters.

For example

If you want to fully harness the power of AWS efficiently then using CLI is a “must-have” skill.

Thanks :)

Tech enthusiast