How to Install AWS CLI on Linux, Windows, and Mac
How to Install AWS CLI on Linux, Windows, and Mac

How to Install AWS CLI on Linux, Windows, and Mac

Mayur Chavhan Tutorials

AWS CLI (Command Line Interface) is a command-line tool used by developers and system administrators to interact with AWS services. In this tutorial, we will learn how to install AWS CLI on Linux, Windows, and Mac. We will also learn some tips and tricks to make working with AWS CLI easier.

Prerequisites

Before we start, make sure you have the following prerequisites:

  • A Linux, Windows, or Mac machine with administrative privileges
  • Python 2.7.9 or later, or Python 3.4 or later

Installing AWS CLI on Linux

Follow the steps below to install AWS CLI on Linux:

  1. Open the terminal on your Linux machine.

  2. Update the package list:

    sudo apt-get update
    
  3. Install the AWS CLI package:

    sudo apt-get install awscli
    
  4. Verify the installation:

    aws --version
    

    The above command should output the version of AWS CLI installed on your machine.

Installing AWS CLI on Windows

Follow the steps below to install AWS CLI on Windows:

  1. Download the AWS CLI MSI installer for Windows from the official AWS CLI website.

  2. Run the installer and follow the prompts to install AWS CLI.

  3. Open Command Prompt or PowerShell and run the following command:

    aws --version
    

    The above command should output the version of AWS CLI installed on your machine.

Installing AWS CLI on Mac

Follow the steps below to install AWS CLI on Mac:

  1. Open the terminal on your Mac machine.

  2. Install AWS CLI using Homebrew:

    brew install awscli
    
  3. Verify the installation:

    aws --version
    

    The above command should output the version of AWS CLI installed on your machine.

Tips and Tricks

Multiple AWS Profiles

You can configure multiple AWS profiles on your machine. This is useful if you have multiple AWS accounts or if you are working with multiple IAM users.

To create a new AWS profile, run the following command:

aws configure --profile <profile-name>

Replace <profile-name> with the name of your new profile. Follow the prompts to provide your AWS access key, secret access key, region, and output format.

To switch between AWS profiles, specify the profile name when running AWS CLI commands:

aws s3 ls --profile <profile-name>

Using AWS SSO

If your organization uses AWS SSO (Single Sign-On), you can use AWS CLI to log in to your AWS account without providing your AWS access key and secret access key.

To use AWS SSO with AWS CLI, run the following command:

aws sso login --profile <profile-name> --region <aws-region>

Replace <profile-name> with the name of your AWS profile and <aws-region> with the AWS region you want to log in to.

Syncing Files to Amazon S3

You can use AWS CLI to sync files and directories to Amazon S3. This is useful for backing up files to Amazon S3 or for distributing files to a large number of users.

To sync a local directory to an S3 bucket, run the following command:

aws s3 sync /path/to/local/directory s3://<bucket-name>/<prefix>

Replace /path/to/local/directory with the path to your local directory, <bucket-name> with the name of your S3 bucket, and <prefix> with the prefix to use for the uploaded files.

Copying Files Between Amazon S3 Buckets

You can use AWS CLI to copy files between Amazon S3 buckets. This is useful if you want to duplicate files in different buckets or regions.

To copy a file between S3 buckets, run the following command:

aws s3 cp s3://<source-bucket>/<source-key> s3://<destination-bucket>/<destination-key>

Replace <source-bucket> with the name of the source S3 bucket, <source-key> with the key of the source file, <destination-bucket> with the name of the destination S3 bucket, and <destination-key> with the key of the destination file.

Conclusion

In this tutorial, we learned how to install AWS CLI on Linux, Windows, and Mac. We also learned some tips and tricks to make working with AWS CLI easier. With AWS CLI, you can manage your AWS infrastructure from the command line, making it easier to automate common tasks.