
AWS CLI - Simpler than it looks
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.
Setup your local system with the AWS CLI
1. Create AWS Account
2. Download & Install AWS CLI here
3. Configure AWS CLI
- Login into AWS Management Console using your Root User Credential or use any of your existing IAM user Credentials.

2. For setting up AWS CLI we require Security Credential for our account or the user which we are currently using. Security Credentials are similar to that of a typical username and password. For Viewing our Security Credentials we need to open My Security Credentials tab under username like in my case it was my name.

3. Open the Security credentials tab, and then choose Create new access key under the Access Keys Tab.

4. To see the new access key, choose Show. Your credentials resemble the following:
- Access key ID:
AKIAIOSFODNN7EXAMPLE
- Secret access key:
wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
To download the key pair, choose Download .csv file. Store the .csv file with keys in a secure location for future use. Do not share your Access Keys to Anyone.

5. Now we have the Access Key and Secret Access Key, we just need to configure our AWS CLI. To Configure AWS CLI open Command Prompt on your Computer.

6. Now Type the following in your command prompt
aws configure
- You will be asked for your AWS Access Key and AWS Secret Access Key
- Region name - I chose ap-south-1 (Mumbai) just for this tutorial.
- Output Format - I left it to be default that is JSON format.

Do not share your AWS Access Keys to anyone , the key which i have used has been removed from my account after this tutorial was made.
Done !! Your AWS CLI has been Setup.
Working On AWS CLI
Every Task that can be performed in the AWS GUI can easily be performed here in the AWS CLI as well . Do not worry if you don't know any command for AWS CLI , AWS offers help in every step so that the user can easily set up his or her requirement on AWS using AWS CLI.
“help” is used to know all the commands that are available in AWS. You can also use “help” with sub commands to know the different options available in the respective sub commands.
To access help given by AWS we need to type the following command
aws help

Some Example Tasks on AWS CLI
1. CREATING A KEY PAIR

Key Pair is a set of security credentials that we use to prove our identity when connecting to an instance. Key Pair comes under EC2 Service , To create a key pair we need to use create-key-pair option and to give its name we use --key-name option . For the Demonstration I will create a key pair named “testkeypair”.
aws ec2 create-key-pair --key-name testkeypair
The key Pair will be generated and will be visible on AWS WebUI.

2. CREATING A SECURITY GROUP

Security Group acts as a virtual firewall for your instance to control inbound and outbound traffics. Since Security Groups are used to protect our instances therefore security groups comes under EC2 service. To create a new security group we need to use create-security-group option after ec2. We need to name our Security Group and provide a description about the security group so that it can be convenient. To do this we need to use --group-name and --description option. For the Demonstration I will create a security group named “TestSG” and provide “Demonstration Test” as description.
aws ec2 create-security-group --group-name TestSG --description "Demonstration Test"
Our Security Group has been created.

3. LAUNCH AN INSTANCE

To launch a new instance we need to use run-instances option under ec2. Using aws ec2 run-instances help we get to know that — image-id , — count, — instance-type, — key-name, — security-group-ids are some options which are mandatory for launching an instance. For the Demonstration I will be using the key pair and the security group that I have created above.
aws ec2 run-instances --image-id ami-0e306788ff2473ccb --count 1 --instance-type t2.micro --key-name testkeypair --security-group-ids sg-04cf5e13cde6412f3
Our Instance has been launched.

4. Creating An EBS Volume
EBS comes under EC2 service. So to create an EBS volume we need to use create-volume option under aws ec2. For creating EBS volume we would have to specify --availability-zone,--size,--volume-type of the EBS that we want to create. For this Demonstration I will create an EBS of Size 1GB of type gp2 and in ap-south-1a(Mumbai) Region.
aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a
Our EBS Volume has been created.


5. Attaching EBS to Instance
For attaching an EBS volume to a specific instance, we need to use attach-volume command. For attaching our EBS we need to provide --instance-id, --volume-id, --device option for our EBS and the instance which we want our EBS to connect to. For the Demonstration I will connect my above created EBS to my instance having instance id as “i-063e1b0089f6f9c34”.
aws ec2 attach-volume --instance-id i-063e1b0089f6f9c34 --volume-id vol-0fae957e590bfe175 --device /dev/sdh

To verify we can go to our EBS under EC2 Service in our AWS WebUI to confirm that our EBS has been successfully attached to the instance.

AWS has provided a very user friendly tool through AWS CLI to easily manage and update it’s cloud offerings and services. It offers help with each and every step, making it a choice even for non programmers.