A developer is running a Python application locally using the AWS SDK for Python (Boto3) to retrieve objects from an Amazon S3 bucket.
The developer's local terminal has the following environment variables configured:
bash
export AWS_ACCESS_KEY_ID=AKIA111111111EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_PROFILE=staging
The shared AWS credentials file (`~/.aws/credentials`) contains:
ini
[staging]
aws_access_key_id = AKIA222222222EXAMPLE
aws_secret_access_key = userSecretKeyStagingExample
The application code is initialized as follows:
python
import boto3
s3 = boto3.client('s3')
response = s3.list_objects_v2(Bucket='my-staging-bucket')
When the developer runs the application, it fails with an `AccessDenied` error. The IAM user represented by `AKIA111111111EXAMPLE` does not have access to the S3 bucket, but the IAM user in the `staging` profile (`AKIA222222222EXAMPLE`) has full S3 permissions.
What is the reason for this failure, and how should the developer resolve it?
- AThe default credential provider chain ignores environment variables when a profile is specified. The developer must modify the application code to hardcode the credentials by passing the aws_access_key_id and aws_secret_access_key parameters directly to the client constructor.
- BThe staging profile credentials cannot be used locally because the IAM user has not configured a trust policy that allows the local workstation's IP address. The developer must add a trust policy to the IAM user permitting access from the local public IP.
- The default credential provider chain evaluates the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables before evaluating AWS_PROFILE. The developer should unset the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables in the terminal.Cevap
- DThe SDK requires local developer credentials to be retrieved dynamically from Systems Manager Parameter Store with automatic rotation configured. The developer must migrate the local credentials to Parameter Store and fetch them in the code.