Managing AWS resources using CLI

Backbencher05
7 min readOct 20, 2020

Before we move toward using AWS resources , let’s talk about AWS Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet. AWS’s version of virtual computers emulates most of the attributes of a real computer, including hardware central processing units (CPUs) and graphics processing units (GPUs) for processing; local/RAM memory; hard-disk/SSD storage; a choice of operating systems; networking; and pre-loaded application software such as web servers, databases, and customer relationship management (CRM).

The AWS technology is implemented at server farms throughout the world, and maintained by the Amazon subsidiary. Fees are based on a combination of usage (known as a “Pay-as-you-go” model), hardware, operating system, software, or networking features chosen by the subscriber required availability, redundancy, security, and service options. Subscribers can pay for a single virtual AWS computer, a dedicated physical computer, or clusters of either. As part of the subscription agreement, Amazon provides security for subscribers’ systems. AWS operates from many global geographical regions including 6 in North America.

Amazon markets AWS to subscribers as a way of obtaining large scale computing capacity more quickly and cheaply than building an actual physical server farm. All services are billed based on usage, but each service measures usage in varying ways. As of 2017, AWS owns a dominant 33% of all cloud (IaaS, PaaS) while the next two competitors Microsoft and Google have 18%, 9% respectively according to Synergy Group

To access AWS and use there resources various ways are availabe

  • GUI — have Beautiful Web Portal
  • CLI
  • Writing Some Script in some language
  1. GUI — Web Portal

For using AWS services we can directly login with Web Portal and use there services , you have to create account and login than use there services

But here we are going to use second option i.e CLI (Command line Interface why ?

because using CLI we can do multiple thing that we cant do using GUI , Yes I know , using Graphical way GUI we just click and click and configure what we want ,

But working with CLI is very interesting for that you need some program which give you facility to work with CLI for that you have to download it as per your requirement either for windows , Linux or any other am providing you link to download for windows

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

Download and install it

Now , to access / use the resources of aws you have to provide use the command #aws Configure

  • Access-key
  • Secret Key
  • Region
  • Output format

But From where you get all the thing , for that u have To use one service of AWS i.e IAM ( Identity and Access manager ) So go to AWS portal and create user , you can make user and grant permission from CLI also but here am creating user from portal

Click on ADD user

for here you can get your access key and Secret Key

than after login you can do what you want like u do from GUI

Here am going to perform one Task

Task Description — AWS 👨🏻‍💻

🔅 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.

All the above steps must be performed using AWS CLI

“Before running any command , I want to say that while you type any command you always thing what is the command or what i have to write to use the particular resources ,For that Don’t remember the command always remember your requirement what you want “

let i want to work on ec2 service that type aws ac2 help which give you all the command and beautiful manual than use the arguments what you want

1. Create a key pair

# aws ec2 create-key-pair help

# aws ec2 create-key-pair — key-name forawstask1

2. Create a security group

# aws ec2 create-security-group — description task1 — group-name task1

Now after security group create we have to set the Rules

for creating Rule we have think what we want means which port you want to allow here I allow port 22 and port 80

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

# aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — count 1 — subnet-id subnet-b1edd7d9 — security-group-ids sg-0819918749b7884dd — key-name forawstask1

using this command we launch one AWS instance using CLI , I know after seeing this command u thing how big is this command , how can i remember this command ?

for that i just want to say that don’t remember the command just put what u want like i have first understand my need and there are manual available or run the help command

# aws ec2 run-instances help you see lot of option use as your requirement

using this command we launch one instance that have key-pair and security group that we already created

4. Create an EBS volume of 1 GB.

Before creating EBS volume let’s talk about

  • what is EBS
  • why we need EBS

EBS ( Elastic Block Storage ) , The name itself give you the meeting i.e Storage , To store or data permanent / persistent we need the storage device , as we store our data in some device were our OS/instance is running but what if our storage goes down /corrupt we loose everything i.e our running os as well as data

To overcome with this problem we attach extra storage were we store all the data like we attach a external hart disk or pen drive AWS also provide the service to attach the extra hard disk EBS

5. The final step is to attach the above created EBS volume to the instance you created in the previous steps.

# aws ec2 attach-volume — volume-id vol-0d5edc8cef69e89eb — instance-id i-06771e4270c2ae148 — device /dev/sdf

we also see in our instance it is attached

Thank you

feel free to ask the querry

linkedin — linkedin.com/in/aditya-kumar-soni-91370b189

--

--