How to install and configure AWS CLI on ubuntu
AWS is an excellent cloud service provider. One of the reasons for its popularity is the easy to use web interface and the wide range of services offered.
AWS also provides a rich set command line based tool to access different services. These handy tools enable developers to automate, configure and manage AWS cloud resources from a Linux terminal.
In this post, we’ll walk through the process of installing and configuring the AWS CLI and see an example of how easy it use to create and manage AWS resources.
What is the AWS CLI
AWS CLI is a tool that pulls all the AWS services together in one central console, enabling developers to easily control and configure multiple AWS services using a command line interface.
It reduces and in some cases eliminates the dependency of navigating & interacting with
The AWS CLI is an open source tool built on top of the AWS SDK for Python (Boto) that provides commands for interacting with AWS services. With minimal configuration, you can start using all of the functionality provided by the AWS Management Console from your terminal.
How to install AWS CLI on ubuntu
To install AWS CLI you will need an AWS account, in order to get an access key ID and secret access key and Python installed on your ubuntu development desktop.
There are two methods you can choose to install the AWS CLI on your Ubuntu Laptop, both will deliver the same result so you can choose whichever is best for you. We’ll provide both so can choose.
How to install the AWS CLI using PIP
To Install the AWS ClI simply open a terminal window and execute the following command:
Once the command has completed you can then ensure the $PATH to AWS CLI is configured which enables you to globally use the command
ensure you refresh your bash profile by either closing the terminal window and reopening it or by using
How to Install AWS CLI on Ubuntu via Ubuntu repository
Alternatively, you can install the AWS CLI directly from the default Ubuntu repositories.
Once install has completed you can confirm the version using
The console will respond with something similar too
Configure AWS Cli
Before using aws-cli, you need to configure your AWS credentials. You can do this in several ways:
- Environment variables
- Shared credentials file
- Config file
- IAM Role
The quickest way to get started is to
You will be prompted for your credentials. You will need to create IAM account details. You should not use your AWS Root account details.
After completion of this step the AWS CLI has now been configured on your machine and ready for use.
Detailed information of the
aws configure check out the Configuring the AWS CLI
Quick example to test AWS CLI
In order to illustrate how easy it is to use the AWS CLI to manage and configure AWS resources we will run through the process of creating and deleting an Amazon Simple Storage (S3) container.
The first step to check out what is available is simply to call up the help file for the aws s3 commands
We can use the AWS CLI to list all the S3 buckets we have access too with our account
all your S3 bucket names will be displayed in your terminal window.
We can create a bucket using the following command and optionally set the region if you would like to create a bucket in a region other than the default region you configured.
We can also delete the bucket by issuing a similar command but changing it slightly to use rb
If you have an entire directory of files you want to load up to test you don’t have to add them line by line. The AWS CLI comes with some great flexible option switches you can use to simply load up all documents in the in a directory.
An example of this, say you wanted to load up all the files in your current working directory to an S3 bucket. You could use the following command with the additional
Benefits of the AWS CLI
The main benefits of the AWS CLI, that it saves developers time and frustration from having to the AWS Management Console. Thus enabling easier installs, support of all services, automating processes and commands from a familiar terminal command environment.
- Easier to install. Smooth, quick, simple, and standardized.
- Supports all Amazon Web Services. you control all the services from one simple tool.
- Saves time. Developers find it faster and easier to use the AWS CLI once they reach a certain level of proficiency.
- Scripting. The ability to automate control of all Amazon’s web services with scripts. Shell scripts make it easy to fully automate cloud infrastructure.
Configure AWS CLI with Multiple accounts
Developers will typically have several accounts to use across several environments. Fortunately, AWS CLI enables you to configure several profiles to use.
AWS CLI enables you to configure multiple named profiles that are stored in the
You can configure additional profiles by using
aws configure with the
--profile option, or by adding entries to the
If you want to create profile for
development then simply execute the configure with the switch
You can then add your development specific AWS Key and Secret and Region details. You can then configure your application to make use of the specific profile should you require.
Developers will often and preferably should have different AWS Keys and Secret to the actual Production keys being utilised. Undoubtedly developers should have separate environments they use for executing, running and testing i.e. Development, Staging and Production Environments.
In all likelihood these environments will connect to different resources so as not to corrupt the Production Data etc.
In .net core you can configure the AWS SDK to retrieve the desired Profile information from the Environment Specific AppSettings files. For instance, you can create an
appsettings.Development.json to make use of the Development Profile.
The convention for all developers to create a development profile eliminates the need for storing AWS Keys and Secrets in the App Settings.
This can also easily be achieved in Node, PHP, Ruby, Go and Python environments by following a similar strategy and making use of those languages configuration options.
Disadvantages of the AWS CLI
- Your Access Keys are stored in plaintext on disk. This is NOT secure.
- You’re always using permanent Access Keys for auth rather than Temporary Access Keys that are rotated.
- Your credentials sit around on disk forever and the default Named Profile gets used for all commands if you forget to specify a different one, which is
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services enabling you with just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.