A Quick Intro To AWS CLI
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.
To use anything in our AWS Cloud, First, we need to login, and to log in, in CLI we have “aws configure” command
If we stuck anywhere while using AWS CLI like if forgot any commands, we can use “aws help” command to take help
To see our VPC’s (Virtual Private Cloud) we can use “aws ec2 describe-vpcs” command
To view subnets we have, we can use “aws e2 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
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
Now for launching the instance we need image-id. So we can see image-id which are owned by amazon by the following command
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
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
Now we have everything that is needed to run an instance so we can run an instance by “run-instances” command
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 -
So now we can use describe volume command to see volumes we have
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
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
Now we are connected to our instance and can do anything here as a normal OS. So let’s Host a Website -
Now anyone can connect to our site from anywhere in the world
Now Finally to Stop or Terminate our Instance we can run following commands
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!!