A developer is troubleshooting a local C# (.NET) console application that uses the AWS SDK for .NET to read objects from an Amazon S3 bucket. The developer has configured the AWS CLI on their workstation with a named profile called `dev-profile` containing valid AWS credentials. However, when executing the application locally, it throws an `AmazonServiceException` indicating that the credentials cannot be found. No environment variables are set on the workstation, and the SDK is initialized using default client configuration. Which of the following actions is the most secure and appropriate way to resolve this credential error for local development?
- Set the AWS_PROFILE environment variable to dev-profile in the local shell environment.Answer
- BHardcode the AWS Access Key ID and Secret Access Key from dev-profile directly into the AmazonS3Client initialization code.
- CStore the dev-profile credentials in AWS Secrets Manager and retrieve them programmatically when the application starts.
- DAdd the workstation's local IP address to the trust policy of the default IAM role to allow local credentials delegation.
Answer
Set the AWS_PROFILE environment variable to dev-profile in the local shell environment.
The correct answer is to set the AWS_PROFILE environment variable to the named profile. The default credential provider chain in the AWS SDK for .NET automatically checks for this variable. If set, it overrides the default profile search and reads the credentials from the matching named block in the shared AWS credentials file. This avoids exposing secrets and requires no modification of the application code.
Step-by-Step Solution
Key Concept
AWS SDK Credential Provider Chain and Named Profiles