Exploring AWS CLI

Exploring AWS CLI

You may be familiar with the various cloud services that Amazon provides. Some of you might have used the web-based console of AWS to launch an EC2 instance or create EBS storage or might have used the fully managed S3 object storage services.

Today, I would like to discuss how we can do all of these using commands from our terminal. AWS CLI is an open source tool that enables you to interact with AWS services using commands in your command-line shell. By running commands, we can achieve almost every functionality that the browser-bases console provides us.

image soruce

Make sure you have installed and configured AWS CLI before following this demo.

For help in installation and configuration, reach out to below URL:

The demonstration in this article would include the following:

1. Creating a key pair

2. Creating a security group

3. Launching an instance using the above created key pair and security group.

4. Creating an EBS volume of 1 GB.

5. Attaching the above created EBS volume to the instance we created in the previous steps.

So, lets begin!

Creating a Key

The –key-name switch is used to give the name of the key and the –output text switch is used to copy the contents of the key into a file which we may use to login in the instance which uses this key.

Creating a Security Group

I have created a security group in default VPC in Mumbai region. Then using the create-tags module, I simply added a ‘Name’ tag to the security group.

I used describe-security-groups module to see the description of the security group. We see that the SG we created has an outbound rule which allows all traffic to pass.

Now, using the authorize-security-group-ingress module, we add a rule that allows SSH traffic on port 22 from anywhere (See CIDR notation —

Launching an EC2 instance

Now, we intend to launch an ec2 instance using the key and security group created above in the default VPC subnet (ap-south-1a).

Using the run-instances module and specifying the correct parameters we are able to launch an ec2 instance. The output shows the detailed description of the instance.

Creating an EBS volume of 1 GB

EBS is a block storage service provided by AWS. When we launch an instance, by default a root block storage is attached with it. If we want we can add more block storage in the form of EBS volumes to our instances. Here, we will do the same.

First we will create a block storage and later attach it with the instance we created.

Here we created our storage in the same subnet as our instance, since EBS is a regional service.

The last step is to attach this volume to instance.

Attaching instance

Thus, we attached the volume to the device successfully.

Thank you for reading till here. I hope this article helped you understand the basics of AWS CLI.

Note: Just like ec2 there are similar modules available for a variety of tasks.

Use aws <help> to explore more modules like ec2.

Use aws <module> help to more about each one of them. For eg., in ec2 we have sub-commands like ‘create-volume’ , ‘run-instances’ , ‘create-subnet’ etc.

Use aws <module> <sub-command> help for further reference.



Software Engineer | DevOps Enthusiast | Writer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store