AWS Command Line Interface (AWS CLI): A Complete Guide

Home » Amazon Web Services » AWS Command Line Interface (AWS CLI): A Complete Guide
AWS CLI

Amazon provides a myriad of tools which help developers, architects, and administrators to develop and manage AWS cloud services. These include software development kits (SDK), console, command line tools, etc. In this article, we’ll explore the AWS Command Line Interface (AWS CLI) tool in detail – covering its benefits, installation and configuration on different operating systems. We will also discuss some of the most frequently asked questions about the AWS CLI. So let’s find answers to the question – what is AWS CLI?

What is AWS CLI?

AWS CLI is an open source command-based application developed by AWS for easy management of your AWS cloud service. It provides different commands for managing AWS cloud services. It is compatible with the windows command line, Linux/Mac shell programs, and even remote terminals like putty.

Understanding AWS CLI

AWS CLI is a native tool that you can use to make your life easier. You can run commands in the terminal of your operating system. For windows, you can run commands in the command prompt. For Linux and Mac, you can use any shell programs like Bash, Zsh, or Tcsh. You can even run AWS CLI commands on remote EC2 instances through putty or SSH. Just like you would set up and manage different AWS services through its console, you can perform all the functions through the CLI tool.

What is the use of AWS CLI?

AWS CLI is a very useful tool for configuring AWS cloud services, especially the ones requiring multiple steps. You can even automate repetitive tasks through CLI. Automating tasks saves developers time, and they do not need to log in to the console. Once you configure your AWS credentials, you do not need to provide your credentials again and again – unlike the console application, where you are required to provide your credentials every time you access your AWS cloud services.

Benefits of AWS CLI

AWS CLI provides loads of benefits, including:

  • It is a unified tool through which you can access all of your cloud services from a single tool. Note that Amazon has over 200 services.
  • The installation and configuration of CLI are very easy. In the upcoming section, we will guide you through the installation and configuration of AWS CLI on different operating systems.
  • You can automate the management of your AWS services through scripts. The provisioning and management of your cloud infrastructure can be automated through shell scripts.
  • AWS CLI saves you a lot of time – as you can perform multiple steps and complex operations with just a few commands,

Types of AWS CLI

There are two types of CLI tools offered by AWS:

  1. The AWS CLI tool which we cover in this article. You install it locally on your computer, and you can only use it on the systems you have installed and configured it.
  2. AWS CloudShell is a browser-based shell that you can launch directly from your AWS console and run the standard CLI commands. CloudShell is an extension to the AWS CLI and offers many advantages compared to AWS CLI. You do not need to install any tool here; you can access it from anywhere. Note that AWS CloudShell is not available in all AWS regions.

How to download and install AWS CLI

Windows Installation

  1. Download AWS CLI v2 for windows.
  2. After downloading, run the AWS CLI MSI installer and complete the installation steps.
  1. To confirm the installation, open the Start menu in windows, search for “cmd” to open a command prompt, and use the “aws –version” command in cmd.

Mac Installation

  1. Download AWS CLI v2 for Mac.
  2. After downloading, run the AWS CLI MSI installer and complete the installation steps.
  1. To confirm the installation, open the terminal and use the following commands:
  2. $ which aws
  3. $ aws –version

Linux Installation

  1. Open the terminal of your choice and execute the following commands to download and install AWS CLI
  • curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”
  • unzip awscliv2.zip
  • sudo ./aws/install
  1. Run the “aws –version” command to verify it is installed.

Configure AWS CLI

To configure AWS CLI, you must first generate the AWS credentials. You need to have the permissions to generate the credentials.

How to generate AWS CLI Credentials

The following items are required to set up and manage AWS services with AWS CLI:

  1. An AWS account
  2. IAM user credentials
  3. IAM access key pair generated by the IAM user

When you run the AWS CLI commands, the AWS CLI accesses these AWS credentials. Creating AWS credentials is therefore mandatory for using AWS CLI.

Note: Never use a root account for managing and creating services. Best practice is to always use an IAM account (IAM user).

Steps to generate AWS credentials

  1. Log in in to the AWS Management Console and search for IAM.
  1. In the navigation pane, select Users link.
  2. In the Users section, Select the name of the user whose access keys you want to create.
  1. Click on the Security credentials tab.
  1. In the Access keys section, choose Create access key.
  2. To view the new access key pair, select Show.

Now that you have the credentials for AWS, you can start configuring your CLI tool.

How to configure AWS Credentials on Windows

Run the command “aws configure” in cmd to start setting up the configuration. Once we enter this command, AWS CLI prompts us with four pieces of information:

  1. Access Key ID: (enter your id)
  2. Secret Access Key: (enter your key)
  3. AWS Region: (enter the desired location)
  4. Output Format: (enter desired output)

Once the configuration is complete, and you can create/manage different services in AWS through the terminal.

How to configure AWS Credentials on Linux

Execute the command “aws configure” in the terminal to set up the configuration. Once we enter this command, AWS CLI prompts us with four pieces of information:

  1. Access Key ID: (enter your id)
  2. Secret Access Key: (enter your key)
  3. AWS Region: (enter the desired location)
  4. Output Format: (enter desired output)

The configuration is complete, and you can create/manage different services in AWS through the terminal.

Configure AWS Credentials on Mac

Execute the command “aws configure” in the terminal to set up the configuration. Once we enter this command, AWS CLI prompts us with four pieces of information:

  1. Access Key ID: (enter your id)
  2. Secret Access Key: (enter your key)
  3. AWS Region: (enter the desired location)
  4. Output Format: (enter desired output)

Once the configuration is complete, you can create/manage different services in AWS through the terminal.

Commonly Used Commands in AWS CLI

Some of the most common CLI commands are the following:

Configuration Commands

Create profiles:

aws configure –profile profilename

Output format:

aws configure output format

To specify your AWS region:

aws configure region (region-name)

Amazon EC2 Commands

Launch an Amazon EC2 instance (must update the AMI ID):

aws ec2 run-instances –instance-type t2.micro –image-id ami-0f5411afa59916e0e –region us-east-1

Amazon API Gateway Commands

List API Gateway IDs and names:

aws apigateway get-rest-apis | jq -r ‘.items[] | .id+” “+.name’

List API Gateway Keys:

aws apigateway get-api-keys | jq -r ‘.items[] | .id+” “+.name’

Amazon CloudFront

List CloudFront distributions and origins:

aws cloudfront list-distributions | jq -r ‘.DistributionList.Items[ ] | .DomainName+ “ “+Origins.Items[0].DomainName’

Amazon CloudWatch

List information about an alarm:

aws cloudwatch describe-alarms | jq -r ‘.MetricAlarms[ ] | .AlarmName+” “+.Namespace+” “+.StateValue’

Amazon DynamoDB

List DynamoDB tables:

aws dynamodb list-tables –region ap-southeast-2 // replace with your region

Get all items from a table:

aws dynamodb scan –table-name events // replace with your table name

IAM Group

List groups:

aws iam list-groups | jq -r .Groups[ ].GroupName

Add/Delete groups:

aws iam create-group –group-name (groupName)

IAM User

Get single user:

aws iam get-user –user-name (username)

Add user:

aws iam create-user –user-name (username)

Delete user:

aws iam delete-user –user-name (username)

Frequently asked questions

What is the main function of the AWS command line interface?

The AWS command line interface (AWS CLI) is a unified all-in-in tool through which you can control and manage all your AWS cloud services. Through the AWS CLI, you can automate work through shell scripts. AWS CLI gives you access to all AWS API’s and cloud services.

What is the difference between AWS CLI and AWS Console?

The AWS console is a web-based application by AWS, which you can easily use to manage your AWS services. AWS CLI is also a handy tool to configure AWS services quickly. The AWS CLI may come with a learning curve, while the AWS console does not need much expertise. Viewing reports or dashboards is the best use case for the AWS console.

How to check if AWS CLI is installed on your system?

It is very easy to confirm if AWS CLI is currently installed on your system or not. Just run the command “aws –version” in your command prompt or terminal. If CLI is installed, then you will see the version of the installed CLI. If you get an error message such as “AWS is not recognized, ” it means that the AWS CLI is not installed.

Does AWS CLI use bash?

AWS CLI is an open source native tool built on top of AWS SDK for python. AWS CLI supports many shell programs like bash, Tcsh, Zsh, etc.

Is AWS CLI available in Lambda?

Yes, you can use AWS CLI inside the lambda function. You will need to create a lambda layer and include all the dependencies of CLI in the deployment package. For detailed info, click here.

Where does AWS CLI store credentials?

In windows, the credentials are stored at C:\Users\{USERNAME}\.aws\credentials, and on Linux and Mac, the location is ~/.aws/credentials
It will contain the credentials for the default profile and other named profiles.

Is AWS CLI essential for AWS certifications?

Yes, both the AWS Solutions Architect Associate as well as the AWS SysOps Administrator Associate exam require practical knowledge of AWS CLI. You need to know the syntax of different commands, and you should also know the relevant commands to manage common cloud services like EC2, S3, EBS, etc.

Conclusion

In this article, we discussed the AWS CLI in detail. After going through this article, you should be able to understand what the AWS CLI is, where you use it and how to install/configure it on your operating system. AWS CLI is an important tool in your AWS arsenal. You must have a good command of to master AWS services. Strong knowledge of AWS CLI is a prerequisite for many AWS certifications, such as the AWS Solutions Architect Associate and the AWS SysOps Administrator Associate.

Learn how to Master the Cloud

AWS Training – Our popular AWS training will maximize your chances of passing your AWS certification the first time.
Membership – For unlimited access to our entire cloud training catalog, enroll in our monthly or annual membership program.
Challenge Labs – Build hands-on cloud skills in a secure sandbox environment. Learn, build, test and fail forward without risking unexpected cloud bills.

Related posts:

Responses

Your email address will not be published. Required fields are marked *