Closed mgryszko closed 2 years ago
Hi @mgryszko,
Thanks for opening. Based on your example, it looks like you're trying to work around not being able to use credential_source
without assuming a role (since you're chaining here), or alongside source_profile
. This is by design as explicitly using a profile is intended to override the precedence of using environment variables:
Your request is noted though, and is similar to another recent issue: https://github.com/aws/aws-cli/issues/6042#issuecomment-807073577
If you can provide some more background as to what you are limited in doing based on the current behavior, that would be useful feedback.
As to the technical behavior, this functionality is part of botocore
, and a configparser.RawConfigParser
object is used:
Interpolation is not used by default in a RawConfigParser
:
https://docs.python.org/3/library/configparser.html#rawconfigparser-objects
Legacy variant of the ConfigParser. It has interpolation disabled by default and allows for non-string section names, option names, and values via its unsafe add_section and set methods, as well as the legacy defaults= keyword argument handling.
Hi @kdaily,
Huge thanks for so detailed response.
Regarding the configuration precedence - according to the documentation link you provided, it looks like CLI options trump over env variables, env variables trump over CLI credentials file, etc. Even if my default
profile inherits from the root
profile, if I define the environment variables (AWS_...
), they should override what's in the config/credentials file. At least this is my understanding when reading the documentation. Maybe the doc be updated to reflect this behaviour?
Regarding my use case: I was trying to execute aws-cli
in a Docker container. The Docker image has a generic .aws/credentials
file with aws_access_key_id
and aws_secret_access_key
pointing to env variables. The env variables are passed through the docker-compose.yml
.
The documentation linked earlier does describe how environment variables take precedence over profile configurations. I'm not sure if I understand what the discrepancy is in the documentation. Could you please elaborate on which part you think should be updated/clarified?
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.
Confirm by changing [ ] to [x] below to ensure that it's a bug:
Describe the bug Credentials cannot be set using environment variable interpolation.
SDK version number
aws-cli/2.1.34 Python/3.9.2 Darwin/20.3.0 source/x86_64 prompt/off
Platform/OS/Hardware/Device macOS BigSur
To Reproduce (observed behavior)
Define env variables
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
.Create
~/.aws/credentials
with the following content:Assuming here Python configparser syntax.
aws configure list
output:Credentials are read
aws --profile default --region eu-central-1 s3 ls
output:Expected behavior Environment variables are interpolated correctly by commands in the credentials file.
Logs/output
Additional context Profiles are defined in
~/.aws/config
inheriting fromroot
: