aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

Ability to specify / configure where the alias config file (`~/.aws/cli/alias`) is located

Open isleshocky77 opened this issue 9 months ago • 3 comments

Describe the feature

The class for AliasLoader allows you to send to it a location of the file.

https://github.com/aws/aws-cli/blob/a5b944a28a93967810e25563044450a6de7e64ce/awscli/alias.py#L34

However, in practice, the CliDriver does not make use of this.

https://github.com/aws/aws-cli/blob/a5b944a28a93967810e25563044450a6de7e64ce/awscli/clidriver.py#L106

Only the unit tests do make use of this.

https://github.com/aws/aws-cli/blob/a5b944a28a93967810e25563044450a6de7e64ce/tests/unit/test_alias.py#L45

Because of this, there is no way to specify a location different than ~/.aws/cli/alias to hold aliases.

Use Case

If you have more than one aws account or role you might want to have different aliases for each of those.

You can use environment variables (e.g. AWS_CONFIG_FILE) to change the location of the config file; however, using environment variables or even a config setting in the config file, there is no way to change the location of the cli alias config file.

Proposed Solution

  1. Allow for configuring the location of aws cli home (e.g. ~/.aws)
    • #9416
  2. Allow for an environment variable to configure the alias config file (e.g. AWS_CLI_ALIAS_FILE=~/.aws/cli/alias)
  3. Allow for the aws config file to specify these files per profile
# ~/.aws/config

[profile test1]
cli_alias_file = ~/.aws/cli/alias

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

CLI version used

aws-cli/2.17.32 Python/3.11.9 Linux/6.11.0-21-generic exe/x86_64.ubuntu.24

Environment details (OS name and version, etc.)

Ubuntu 24.04.2 LTS

isleshocky77 avatar Mar 31 '25 19:03 isleshocky77

Feature Description: Customizable AWS CLI Alias File Location

Current Behavior:

The AWS CLI's AliasLoader class supports specifying a custom file location for aliases through its constructor parameter alias_filename. However, this functionality isn't utilized by the CliDriver, which initializes AliasLoader without providing a file path (defaulting to ~/.aws/cli/alias). Only unit tests currently leverage this parameter.

Problem:

Users managing multiple AWS accounts/roles cannot specify different alias files per profile/environment. While other AWS CLI configurations (like AWS_CONFIG_FILE) support customization, alias file locations are hardcoded.

Proposed Solutions:

  1. Environment Variable Support
    Introduce AWS_CLI_ALIAS_FILE to override the default path (e.g., AWS_CLI_ALIAS_FILE=~/.aws/account1/alias).

  2. Config File Support
    Allow per-profile alias file paths in ~/.aws/config:

    [profile test1]
    cli_alias_file = ~/.aws/test1/alias
    
  3. AWS CLI Home Directory Customization
    Extend #9416 to let users redefine ~/.aws globally (e.g., via AWS_CLI_HOME).

Impact:

  • Backward Compatibility: Default behavior remains unchanged unless new variables/configs are used.
  • Breaking Changes: Possible if users rely on the hardcoded path assumption.

Implementation Notes:

  • The CliDriver should check (in order):
    1. Profile-specific cli_alias_file in ~/.aws/config.
    2. AWS_CLI_ALIAS_FILE environment variable.
    3. Default path (~/.aws/cli/alias).
  • Unit tests already validate custom paths; integration tests would be needed for the new hierarchy.

User Benefit:

  • Flexibility: Different alias sets per account/role (e.g., prod vs. dev profiles).
  • Consistency: Aligns with AWS CLI's existing customization patterns (e.g., AWS_CONFIG_FILE).

Example Workflow:

# Using environment variable
export AWS_CLI_ALIAS_FILE=~/.aws/dev/alias
aws dev-profile s3 ls  # Uses aliases from custom file

# Using profile-specific config
cat ~/.aws/config
[profile dev]
cli_alias_file = ~/.aws/dev/alias

Additional Context:

  • CLI Version: aws-cli/2.17.32.
  • OS: Ubuntu 24.04.
  • Priority: Minor (p3), but useful for multi-account users.

Next Steps:

  1. Approval: Confirm design aligns with AWS CLI’s configuration philosophy.
  2. Implementation: Modify CliDriver to support the proposed lookup hierarchy.
  3. Testing: Expand tests to cover profile/environment-driven paths.

imSanko avatar Apr 10 '25 03:04 imSanko

Can I work on this issue?

imSanko avatar Apr 10 '25 03:04 imSanko

Hello @isleshocky77, thanks for reaching out. This feature request and we are tracking it here and for any duplicates: https://github.com/aws/aws-cli/issues/9031 . Although, I will bring this up to the team. If you have any other questions, please do let me know. Thanks.

adev-code avatar Jun 09 '25 20:06 adev-code

Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.

github-actions[bot] avatar Jun 19 '25 21:06 github-actions[bot]