Getting Started With AWS CLIv2

Saumy Srivastava
The Startup
Published in
7 min readJan 9, 2021

-Unified tool to manage your AWS services from a terminal session on your own client.

In the journey as the ARTH Learner in the program “ARTH -2020” under the guidance of ‘The World Record Holder Mr. Vimal Daga Sir, I got to explore more and here I’m sharing some learnings.

We usually may have come across the term ‘AWS’ too frequently in our life. But ever ponder that, ‘What is AWS?’ To understand AWS, it’s importance and benefits offered by AWS, visit — AWS: A Support System for Startups.

Now, What is AWS CLI? I’ll try to outline it all here, including an Intro to AWS CLI, Installing AWS CLI, Configuration of AWS CLI and many more things.

What Is AWS CLI??

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

The ‘AWS CLIv2 (version 2)’ is the most recent major version of the AWS CLI and supports all of the latest features. Some features introduced in version 2 are not backported to version 1 and you must upgrade to access those features.

To Learn More about AWS CLI: aws.amazon.com-cli.

Make sure you have Created one user using IAM Service of AWS :

✔ To start using the AWS services first we need to login to the AWS account that is Authentication is must and this can be achieve by creating a IAM user.

➔ Click on Add user to create a new user

Creating a new user

➔ Now give any user name and select Programmatic Access and this will provide the Access Key and Secret Key and then click on AWS management console access and choose the custom password option and type your own password then click on next permissions.

Setting User Details and Access Type

➔ Now click on Attach existing policies directly option and choose the PowerUserAccess.

Selecting Power User Access

➔ Then give the tag if want but it is optional.

Giving the tag if required

➔ Then click on create user and user will be successfully created by the name ‘Virat’.

Click on Create User

➔ Then download the .csv file this contains the access key and secret keys.

Download .csv file

🎇Installing AWS CLI :

✔ The Installation of AWS CLI is quite simple. You just have to download the application compatible with your Operating System from the link provided below and just install it as you install any-other software in your system.

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

✔ After installing the AWS CLI go to the command prompt of windows and run the below command for checking that the software is successfully installed.

AWS CLI successfully installed

🎇AWS CLI Configuration :

✔ To authenticate our AWS CLI with our AWS account, for that go to the command line and type the below mentioned command:

aws configure

✔ Next, you have to provide the “access key” and “secret key” and then provide region means on which region you want to work on and also give the output format as “json”. After that, press enter.

✔ If no error comes up then you are successfully logged in.

✔ Now to run commands in AWS CLI you should have some knowledge of AWS and its services. For that, the documentation by AWS is best to read and understand. Simple way is to use ‘aws help’ command which will lead us to great insights.

Link: https://docs.aws.amazon.com/cli/index.html

🎇Also, in this article we are going to discuss the below mentioned tasks.

  • Creating a key pair
  • Creating a security group
  • Launching an instance using the above created key pair and security group.
  • Creating an EBS volume of 1 GB.
  • The final step will be to attach the above created EBS volume to the instance you created in the previous steps.

✨Let’s get Started!✨

🎇 Creating a key pair

✔ To create a key pair we need to run the below mentioned command :

aws ec2 create-key-pair — key-name <KeyName>

✔ Key created with key name as “samkey1”

✔ To confirm the key pair is successfully created just go to the webUI & check.

Confirmation in AWS console

Note : Change the region in which we have created the user account on the right top corner if the user doesn’t appears.

✔ To describe all the key pairs run the command :

aws ec2 describe-key-pairs

To describe all key-pairs

✔ We can also see more options using help , so here our first objective is completed.

🎇 Creating a Security Group

✔ To create a Security Group you can run below mentioned command :

aws ec2 create-security-group — group-name Name — description “Give Description”

✔ Security group created with name “security1”

✔ To confirm the Security Group is successfully created just go to the webUI and check.

Confirmation of Security Group created in AWS Console

✔ By default no inbound rule is created and due to that no one can enter as no protocol is associated so just add the inbound to all traffic.

No Inbound Rules Found by default

✔ To create the inbound rule, we need to run the command :

aws ec2 authorize-security-group-ingress –group-id — protocol tcp –port 22 –cidr 0.0.0.0/0

Creating Inbound Rule

✔ To confirm the Security Group is successfully created just go to webUI and check.

New Inbound Rule created for security1

✔ To describe all the security groups run the command :

aws ec2 describe-security-groups

Describe all the security groups

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

✔ To launch the instance run the command :

aws ec2 run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — count 1 — security-group-ids <security-group_id> — key-name <key_name>

Launching an ec2 instance

✔ The ec2 instance is successfully launch and is running. Confirming in AWS console.

EC2 instance launched

🎇Creating an EBS volume of 1 GB

✔ To create an EBS volume of 1GB we have to run the following Command :

aws ec2 create-volume — volume-type <volume type> — size 1 — availability-zone <Zone>

Creating EBS volume from AWS CLI

✔ To confirm the EBS Volume is successfully created just go to webUI and check.

EBS volume of 1 GB created

🎇Attach the above created EBS volume to the instance launched

✔ There is already one volume attached to the instance launched.

8 GB volume already attached

✔ To attach the EBS Volume to ec2 instance through CLI run the command :

aws ec2 attach-volume –volume-id <volume_id> — instanceid <instance_id> — device /dev/sdf

Attaching EBS volume created before

✔ The EBS Volume is successfully attached to the instance, confirming in AWS Console.

1 GB EBS volume attached

These were some of the demos of how we can use AWS CLI and perform the tasks through command line interface. Command Line Interface is used by most of the Professionals, hence to know how to work in cli is much needed for the current scenario of tech field.

Now, that was a whole lot to cover but if you read it, Kudos! 👏👏

Stay tuned for further readings on AWS and some more Tasks on AWS CLI, and Cloud Computing that will be more insightful same as this article and it will have an overview of these services and helps you to understand the power of working in Command Line Interface (CLI).

Stay Safe! Keep Learning!

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

--

--

Saumy Srivastava
The Startup

#techiesam #DevOps Engineer #Cloud Enthusiast #Technology lover #Curious