Table of Contents
The AWS Command Line Interface (AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell. With minimal configuration, the AWS CLI enables you to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in your terminal program:
- Linux shells – Use common shell programs such as bash, zsh, and tcsh to run commands in Linux or macOS.
- Windows command line – On Windows, run commands at the Windows command prompt or in PowerShell.
- Remotely – Run commands on Amazon Elastic Compute Cloud (Amazon EC2) instances through a remote terminal program such as PuTTY or SSH, or with AWS Systems Manager.
All IaaS (infrastructure as a service) AWS administration, management, and access functions in the AWS Management Console are available in the AWS API and CLI. New AWS IaaS features and services provide full AWS Management Console functionality through the API and CLI at launch or within 180 days of launch.
The AWS CLI provides direct access to the public APIs of AWS services. You can explore a service’s capabilities with the AWS CLI, and develop shell scripts to manage your resources. In addition to the low-level, API-equivalent commands, several AWS services provide customizations for the AWS CLI. Customizations can include higher-level commands that simplify using a service with a complex API.
In this post, we will look at installing the AWS Command Line Interface and configuring it.
Installing the AWS CLI
Download the AWS CLI installer:
AWS CLI is available as installer in the following link. Select the file with respect to your operating system and download it.
https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
I am running windows and installed the windows version. Once downloaded, install and move on to the next step.
Verify the Install
Once you have installed AWS CLI, you can check the installation and the version as well. To do that Open CMD and type
aws –version
Configuring the AWS CLI
In this section we will look at the basic settings that the AWS Command Line Interface uses to interact with AWS and how to configure them. These include the security credentials, the default output format, and the default AWS Region.
For general use, the aws configure
command is the fastest way to set up your AWS CLI installation. When you enter this command, the AWS CLI prompts you for four pieces of information:
The AWS CLI stores this information in a profile (a collection of settings) named default in the credentials file. By default, the information in this profile is used when you run an AWS CLI command that doesn’t explicitly specify a profile to use.
The following example shows sample values. Replace them with your own values as described in the following sections.
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRsrRhkUjAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
Access key ID and secret access key
To use the CLI, you must have the programmatic access enabled for your account. You can do that for the particular user using the AWS Management Console or ask your admin to do that. The programmatic access also requires the use of AWS access keys. Read about how to create them here – Create AWS Access key ID and secret access key
Output Format of AWS CLI
The Default output format specifies how the results are formatted. The value can be any of the values in the following list. If you don’t specify an output format, json is used as the default.
- json – The output is formatted as a JSON
- yaml – The output is formatted as a YAML
- string. (Available in the AWS CLI version 2 only.)
- yaml-stream – The output is streamed and formatted as a YAML
- Streaming allows for faster handling of large data types. (Available in the AWS CLI version 2 only.)
- text – The output is formatted as multiple lines of tab-separated string values. This can be useful to pass the output to a text processor, like grep, sed, or awk.
- table – The output is formatted as a table using the characters +|- to form the cell borders. It typically presents the information in a “human-friendly” format that is much easier to read than the others, but not as programmatically useful.
Profiles in AWS CLI
A collection of settings is called a profile. By default, the AWS CLI uses the default profile. You can create and use additional named profiles with varying credentials and settings by specifying the –profile option and assigning a name.
The following example creates a profile named NerdyElectronics.
$ aws configure –profile nerdyelectronics
AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE
AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCd74iojfXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: text
You can then specify a –profile profile name and use the credentials and settings stored under that name. For Example, if you want to use S3 for the profile NerdyElectronics
$ aws s3 ls --profile nerdyelectronics
Update AWS CLI settings
To update these settings, run aws configure again (with or without the –profile parameter, depending on which profile you want to update) and enter new values as appropriate.
Vivek is a Senior Embedded Innovation Specialist. He has been working on Embedded Systems for the past 10 years. He loves to share his knowledge and train those who are interested. Nerdyelectronics.com was started out of this interest.