Ability to specify / configure where the alias config file (`~/.aws/cli/alias`) is located
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
- Allow for configuring the location of aws cli home (e.g.
~/.aws)- #9416
- Allow for an environment variable to configure the alias config file (e.g.
AWS_CLI_ALIAS_FILE=~/.aws/cli/alias) - 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
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:
-
Environment Variable Support
IntroduceAWS_CLI_ALIAS_FILEto override the default path (e.g.,AWS_CLI_ALIAS_FILE=~/.aws/account1/alias). -
Config File Support
Allow per-profile alias file paths in~/.aws/config:[profile test1] cli_alias_file = ~/.aws/test1/alias -
AWS CLI Home Directory Customization
Extend #9416 to let users redefine~/.awsglobally (e.g., viaAWS_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
CliDrivershould check (in order):- Profile-specific
cli_alias_filein~/.aws/config. -
AWS_CLI_ALIAS_FILEenvironment variable. - Default path (
~/.aws/cli/alias).
- Profile-specific
- 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.,
prodvs.devprofiles). -
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:
- Approval: Confirm design aligns with AWS CLI’s configuration philosophy.
-
Implementation: Modify
CliDriverto support the proposed lookup hierarchy. - Testing: Expand tests to cover profile/environment-driven paths.
Can I work on this issue?
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.
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.