Question

Difficulty: MediumTroubleshooting Local Development and AWS Credentials

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?

  1. Set the AWS_PROFILE environment variable to dev-profile in the local shell environment.Answer
  2. B
    Hardcode the AWS Access Key ID and Secret Access Key from dev-profile directly into the AmazonS3Client initialization code.
  3. C
    Store the dev-profile credentials in AWS Secrets Manager and retrieve them programmatically when the application starts.
  4. D
    Add 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

1
Analyze how the AWS SDK for .NET searches for credentials locally.
The default credential provider chain searches environment variables, followed by the shared credentials file (~/.aws/credentials).
Understanding the lookup order helps identify why the named profile was not automatically detected.
2
Identify the root cause of the credential lookup failure.
Since no environment variables are set, the SDK looks for the default profile in the credentials file, but the credentials are saved under the named profile dev-profile.
Named profiles are ignored by default unless explicitly requested via configuration or environment variables.
3
Select the correct mechanism to configure the profile name without changing the source code.
Exporting the AWS_PROFILE environment variable pointing to dev-profile ensures the default chain locates the credentials.
Setting the environment variable is non-intrusive, secure, and adheres to standard configuration precedence.

Key Concept

AWS SDK Credential Provider Chain and Named Profiles
Rate this question