Cloud
AWS
aws-cli
Aws CLI

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):

      [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):

      [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.

    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.

    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:

      export AWS_PROFILE=profile1
    • Windows Command Prompt:

      set AWS_PROFILE=profile1
    • PowerShell:

      $env:AWS_PROFILE="profile1"

Listing All Profiles

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

aws configure list-profiles

This will output a list of all profile names:

default
profile1
profile2

Example Workflow

  1. Configure Profiles:

    aws configure --profile profile1
    aws configure --profile profile2
  2. List Profiles:

    aws configure list-profiles
  3. Use a Specific Profile:

    aws s3 ls --profile profile1
  4. Set a Profile for a Session:

    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.


🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!