> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ahmadraza.in/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS CLI Install

# Introduction

The AWS Command Line Interface (CLI) is a powerful tool for managing AWS services from the command line. This guide covers installation and usage of the AWS CLI, including common commands for managing EC2 instances, S3 buckets, IAM users, DynamoDB tables, and Lambda functions.

## Installation

1. **Download and Install AWS CLI**

   ```bash theme={null}
   curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
   unzip awscliv2.zip
   sudo ./aws/install
   ```

2. **Verify Installation**

   ```bash theme={null}
   aws --version
   ```

## Basic Configuration

1. **Configure AWS CLI**

   ```bash theme={null}
   aws configure
   ```

2. **List AWS CLI Profiles**

   ```bash theme={null}
   aws configure list-profiles
   ```

3. **Get Current AWS CLI Profile**

   ```bash theme={null}
   aws configure get profile
   ```

4. **Export Default Profile**

   ```bash theme={null}
   export AWS_PROFILE=default
   ```

### Storing Multiple Credentials

1. **Edit the AWS CLI Configuration File**:

   The configuration files are located in `~/.aws/credentials` for credentials and `~/.aws/config` for configuration. You can edit these files directly or use the `aws configure` command with the `--profile` option.

   * **Credentials file (`~/.aws/credentials`)**:

     ```plaintext theme={null}
     [default]
     aws_access_key_id = YOUR_DEFAULT_ACCESS_KEY_ID
     aws_secret_access_key = YOUR_DEFAULT_SECRET_ACCESS_KEY

     [profile1]
     aws_access_key_id = YOUR_PROFILE1_ACCESS_KEY_ID
     aws_secret_access_key = YOUR_PROFILE1_SECRET_ACCESS_KEY

     [profile2]
     aws_access_key_id = YOUR_PROFILE2_ACCESS_KEY_ID
     aws_secret_access_key = YOUR_PROFILE2_SECRET_ACCESS_KEY
     ```

   * **Config file (`~/.aws/config`)**:

     ```plaintext theme={null}
     [default]
     region = us-east-1
     output = json

     [profile profile1]
     region = us-west-2
     output = json

     [profile profile2]
     region = eu-west-1
     output = json
     ```

2. **Add Credentials Using AWS CLI**:

   You can also use the `aws configure` command with the `--profile` option to add credentials.

   ```sh theme={null}
   aws configure --profile profile1
   aws configure --profile profile2
   ```

   Follow the prompts to enter the `aws_access_key_id`, `aws_secret_access_key`, `region`, and `output`.

### Using Named Profiles

1. **Specify a Profile for a Single Command**:

   You can specify a profile to use for a single AWS CLI command with the `--profile` option.

   ```sh theme={null}
   aws s3 ls --profile profile1
   ```

2. **Set a Profile as the Default for a Session**:

   You can set the `AWS_PROFILE` environment variable to specify which profile to use for the current session.

   * **Bash**:

     ```sh theme={null}
     export AWS_PROFILE=profile1
     ```

   * **Windows Command Prompt**:

     ```sh theme={null}
     set AWS_PROFILE=profile1
     ```

   * **PowerShell**:

     ```powershell theme={null}
     $env:AWS_PROFILE="profile1"
     ```

### Listing All Profiles

To list all configured profiles, you can use the following command:

```sh theme={null}
aws configure list-profiles
```

This will output a list of all profile names:

```plaintext theme={null}
default
profile1
profile2
```

### Example Workflow

1. **Configure Profiles**:

   ```sh theme={null}
   aws configure --profile profile1
   aws configure --profile profile2
   ```

2. **List Profiles**:

   ```sh theme={null}
   aws configure list-profiles
   ```

3. **Use a Specific Profile**:

   ```sh theme={null}
   aws s3 ls --profile profile1
   ```

4. **Set a Profile for a Session**:

   ```sh theme={null}
   export AWS_PROFILE=profile1
   ```

   Now, any subsequent AWS CLI commands will use `profile1` credentials until you change the profile or close the session.

> By setting up multiple profiles, you can manage and switch between different AWS credentials easily on your local machine.
