Skip to content

AWS CLI: Setup, Configuration, and Best Practices

Published: at 08:30 PM

Table of Contents:

Introduction

The AWS Command Line Interface (CLI) is a powerful tool that allows developers and system administrators to interact with various AWS services using a terminal or command prompt. It provides a unified way to manage AWS resources, automate tasks, and integrate AWS functionality into scripts and applications. Setting up and configuring the AWS CLI is a crucial step in efficiently working with AWS services and streamlining your workflows.


Prerequisites

Before you start setting up the AWS CLI, make sure you have the following prerequisites in place:


Installing the AWS CLI

AWS CLI can be installed on various operating systems, including Windows, macOS, and Linux.

Windows:

macOS:

brew install awscli
pip3 install awscli

Linux:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Configure AWS CLI

After installing the AWS CLI, you need to configure it with your AWS access key and secret access key. Run the following command in your terminal or command prompt:

aws configure

You’ll be prompted to enter the following information:


Multiple Profiles

If you work with multiple AWS accounts or roles, you can create named profiles to easily switch between different configurations. To configure a named profile, use the —profile option with the aws configure command:

aws configure --profile my-profile

You can use the profile by setting this option in the AWS CLI commands:

aws s3 ls --profile my-profile

Configure CLI output

AWS CLI supports different output formats, including JSON, YAML, text, and table. You can set the default output format during the configuration process or override it for specific commands using the —output option.

aws configure set output table

This setting can also be overrided by setting it in the AWS commands:

aws s3 ls --profile my-profile --output json

Validate AWS CLI & Credentials

You can validate the AWS CLI and Credentials that have been set are working properly:

aws sts get-caller-identity --profile my-profile

Output validates the cli command and credentials:

{
  "UserId": "XXXXXXXXXXXXXXXXX:<user-name>",
  "Account": "<account-number>",
  "Arn": "arn:aws:iam::<account-number>:user/<user-name>"
}

Security Considerations

NOTE: I will be creating another post the dives deeper into using IAM Roles.


Resources