Command AWS through CLI

Vijay Raj
5 min readNov 1, 2020

What is INTERFACE ?

It is a way, how we interact with programs. For example, In our real life, while we communicating with people, we can speak or we can convey our thoughts through symbols, similarly in electronic world we have interface where the user can interact with their systems through any one kind of interface. There are 2 prominent interface are GUI and CLI. In this new era we have 2 other interfaces, they are Web UI and Mobile UI. By this ways we can communicate with our machines and ask them to do what we want i.e. open a program, change properties, etc.

why Command Line Interface (CLI) ?

As of user concern, GUI is enough to interact with their machine. In case, you are from developer background, it is good to go with Command Line Interface. While using CLI, we will be able to understand the architect and concept of a program or any other technology more keenly. CLI approach will let us know the correct flow for any technology.

So, to know more clearly about AWS and its Services, we are going how to see how to use AWS in CLI.

To run any command in CLI, we need to install appropriate program. so we need to install AWS CLI program.

For windows user — https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html

using this link, you can install AWS CLI program. You can also find this program for different OS.

After installing the program, you can check using the following command

you will be getting version details of the program. It tells that the program is installed properly.

Task to be performed using CLI are:

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

Create a key pair:

Before going to create key pair, we have to configure the AWS account’s user in CLI. To do that we want to create IAM user in AWS, to use all services we are giving that user an Administrator Access, this access gives user all power except access to billing.

Go to: https://console.aws.amazon.com/iam/home?#/users

Step 1: click add user

Step 2: Type the user name

Step 3: check in the programmatic access and other check in box is optional, but checking in programmatic access is needed to access the AWS through CLI and click Next.

Step 4: choose attach existing policies directly and choose Administrator Access to get user to access AWS account and access all the services except billing and click Next.

Step 5: Add tags related to user and click Next for review

Step 6: Check for the details and click create user

Step 7: IAM user is created

Configuring the AWS user in CLI

command: aws configure

Type the user’s credentials and type the region. In above case, we have already configured created user

now we can create key pair,

command: aws ec2 create-key-pair — key-name cli-key

Create a Security Group

It help to allow the restricted IP and port to access the data. It helps to enhance the security of an instance. There two things, they are inbound and outbound. Inbound is related to traffic to the instances and outbound is related to traffic for other instances or machines.

command: aws ec2 create-security-group — description “security group creation using cli” — group-name cli-sec-grp

To add rule

command: aws ec2 authorize-security-group-ingress — group-name cli-sec-grp — protocol tcp — port 22 — cidr 0.0.0.0/0

To see details of Security Groups:

command: aws ec2 describe-security-groups

Creating an instance using created key pair and security group:

Ec2 is computing service, which is used to create instance. This provide computing power to the instance.

here I use rhel8 image,

command: aws ec2 run-instances --image-id <image id> --instance-type <instance type> --key-name <key name> --security-group-ids <security id> --subnet-id <subnet id> --count 1

creating EBS volume

It is similar to pen drive or portable hard disk which we use as secondary storage devices. It keeps the data persistent and easy for portability between the two or many instances created in cloud.

command: aws ec2 create-volume — availability-zone ap-south-1a — size 1

Attaching EBS Volume to the created Instances

command: aws ec2 attach-volume — device xvdh — instance-id i-0a21b80a618bcf43f — volume-id vol-055a6d4f8c0fab6ba

Now, it becomes easy start AWS with CLI

note: Don’t feel hard to remember the command, use help command.

#awscloud #awscli #aws #vimaldaga #righteducation #educationredefine #rightmentor #worldrecordholder #linuxworld #makingindiafutureready #righeudcation #arthbylw #awsbylw

--

--