A developer is running a Python script on a local workstation to test integration with Amazon S3. The workstation's shared credentials file (`~/.aws/credentials`) contains a profile named `test-profile` with valid access keys. Before executing the script, the developer sets the `AWS_PROFILE` environment variable to `test-profile` in the terminal. However, the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are also set in the same terminal session from a previous task. The script initializes the S3 client using the default constructor `boto3.client('s3')`. Which credentials will the AWS SDK use to authenticate the S3 requests?
- The credentials provided by the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`Answer
- BThe credentials defined in the `test-profile` section of the shared credentials file
- CNo credentials, resulting in a client initialization failure due to conflicting configuration sources
- DThe credentials fetched from the AWS Systems Manager Parameter Store
Answer
The credentials provided by the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
The Default Credential Provider Chain resolves credentials in a specific order. Direct environment variables (specifically AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) are evaluated first, before checking shared credential files or profiles specified by the AWS_PROFILE environment variable. Therefore, the SDK uses the direct environment credentials.
Step-by-Step Solution
Key Concept
AWS SDK Default Credential Provider Chain Precedence
Estimated Time:1m 30s