Question

Difficulty: MediumAWS SDKs and Credential Management

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?

  1. The credentials provided by the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`Answer
  2. B
    The credentials defined in the `test-profile` section of the shared credentials file
  3. C
    No credentials, resulting in a client initialization failure due to conflicting configuration sources
  4. D
    The 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

1
Evaluate the order of precedence in the AWS SDK Default Credential Provider Chain.
The SDK checks environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) before checking shared credentials files or profiles (AWS_PROFILE).
To determine which credentials the default constructor will resolve first.
2
Identify the active environment variables and file configurations.
Both direct credential environment variables and the AWS_PROFILE variable are set.
To verify if multiple conflicting configurations are active.
3
Select the source with the highest precedence.
The direct credential environment variables win, and their values are used by the SDK.
Since environment variables are checked first, the SDK uses them and stops searching the chain.

Key Concept

AWS SDK Default Credential Provider Chain Precedence
Estimated Time:1m 30s
Rate this question