AWS CLI Profiles

Installing AWS CLI

To install the AWS Command Line Interface (CLI):

  • Windows: Download and run the .msi installer from the AWS website. Verify by typing aws --version in the command prompt.
  • macOS: Use Homebrew and run brew install awscli in Terminal. Verify with aws --version.
  • Linux: In Terminal, use sudo apt-get install awscli (most distributions) or sudo dnf install awscli (Fedora). Verify with aws --version.

Confirming your installed version ensures proper AWS service interaction.

Configuring AWS CLI Access Keys

To obtain AWS access keys:

  1. Log into AWS Management Console
  2. Click your username and select "Security Credentials"
  3. In "Access keys", click "Create Access Key"
  4. Download and securely store the CSV file with your keys

Configure keys using AWS CLI:

  1. Open command prompt or Terminal
  2. Type aws configure
  3. Enter your access key ID, secret access key, preferred region, and output format

This saves your input in ~/.aws/credentials and config. Keep these files secure.

Creating Multiple AWS CLI Profiles

Create a new profile using:

aws configure --profile profile_name

For manual configuration, edit ~/.aws/config and ~/.aws/credentials directly.

List existing profiles:

aws configure list-profiles

Use a specific profile by adding --profile profile_name to any AWS CLI command.

For a session-wide switch:

export AWS_PROFILE=profile_name

Switching AWS Profiles

Two main methods for switching profiles:

  1. Using --profile flag: aws s3 ls --profile profile_name
  2. Setting environment variable: export AWS_PROFILE=profile_name

Check active profile:

aws configure list
A developer switching between different AWS CLI profiles

Verifying AWS CLI Configurations

Verify configurations using:

  1. aws configure list: Displays current configuration summary Add --profile profile_name for specific profiles
  2. aws sts get-caller-identity: Confirms access key connection to correct AWS account

Regular verification helps maintain accurate profile configurations.

Effective AWS CLI profile management streamlines workflows when handling multiple accounts. By utilizing named profiles and environment variables, users can seamlessly switch between different AWS accounts or regions from a single command-line interface.

This comprehensive guide enables users to configure and manage multiple AWS CLI profiles, enhancing productivity and security in multi-account environments.

  1. Amazon Web Services. AWS Command Line Interface User Guide.
  2. Amazon Web Services. Working with AWS Credentials.
  3. Amazon Web Services. Named Profiles.
Posted in AWS

Leave a Reply