A Quick Intro To AWS CLI

Aman Jhagrolia
5 min readOct 13, 2020

--

AWS is a well-known Public Cloud platform in the Market. To use AWS we can log in to the AWS site which will provide us dynamic GUI dashboard, where our mouse can be used to control and maintain our cloud. Its very simple to use. But when we move to the real-world scenarios there we have to always work on Black Screen i.e. CLI (Command Line Interface) there we have no GUI dashboard. There we only have to play with commands.

So in this article, we play with some AWS CLI commands. First, all we need is the AWS CLI software installed.

So Let’s Start -

We can check the AWS CLI version by “aws — version” command.

Check Version

To use anything in our AWS Cloud, First, we need to login, and to log in, in CLI we have “aws configure” command

To Configure

If we stuck anywhere while using AWS CLI like if forgot any commands, we can use “aws help” command to take help

Taking Help

To see our VPC’s (Virtual Private Cloud) we can use “aws ec2 describe-vpcs” command

Describe VPCs

To view subnets we have, we can use “aws e2 describe-subnets”

Describe Subnets

Now we move towards Launching an Instance (OS) in AWS. And for launching an Instance we need to specify that in which Subnet we want to launch our instance. Also, we need to give AMI ID, Instance Type, Security Group. By default, AWS provides one default SG for us, But here we create new SG and also add some rules to it.

So Lets first create a Security Group

Creating Security Group

No adding TCP and HTTP rules to our Security Group and by adding TCP rule we can connect to our instance over SSH and by adding HTTP rule clients from anywhere in the world can connect to our webserver

Adding Rules to SG

Now for launching the instance we need image-id. So we can see image-id which are owned by amazon by the following command

Describe AMIs

Also, we can list the instance types by “describe-instance-types” command, but it will give a long list, so we can filter instance types by — filter option

Describe Instance Types

Now as we know to use any OS, we need to log in first, so here we use keys to login in our instance, So first we need to create the key-pair before launching the OS

Creating Key Pair

Now we have everything that is needed to run an instance so we can run an instance by “run-instances” command

Launch Instance

The most important thing for us is our Data. By default, AWS provides some storage in which they install OS, but that storage is Ephermal in nature if our OS somehow gets terminated then our data in that storage is gets lost. So to protect our data we need Persistance storage. For this, we need to add some extra block storage to our OS.

Creating Volume -

Create Volume

So now we can use describe volume command to see volumes we have

Describe Volume

In the above image, we can see that we have two volumes one of 8 GiB and another of 1GiB that we have created, But we can see that our 1GiB persistence storage is not attached to any instance. So after creating the volume we need to attach that volume with our instance

Attach Volume

Now Our volume is attached to our instance and now we need and make partition of this volume, format it and mount it to use and to do so we need to connect to our instance and we can connect to our instance over SSH providing our Key file

Connect to Instance

Now we are connected to our instance and can do anything here as a normal OS. So let’s Host a Website -

Configure Webserver

Now anyone can connect to our site from anywhere in the world

Connected to Site

Now Finally to Stop or Terminate our Instance we can run following commands

Stop or Terminate the Instances

If the instance is stopped then we can again start the instance, but if we terminate an instance it cant be restarted. To start the stopped instance run the following command -

Thanks, Hope it will help you!!

--

--