A developer is testing a local Java application that uses the AWS SDK for Java v2 to retrieve messages from an Amazon SQS queue. The application is configured to use a profile named dev-profile. When running the application locally, it fails with the following error:
software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain
The developer verifies that the local AWS credentials and configuration files exist. Which TWO conditions could explain this credential loading failure? (Select TWO).
- The credentials file (~/.aws/credentials) defines the profile as [profile dev-profile] instead of [dev-profile].Answer
- The environment variable AWS_PROFILE is not set on the local machine, and the ~/.aws/credentials file does not contain a [default] profile.Answer
- CThe developer configured the credentials in the Systems Manager Parameter Store under the name dev-profile, which the SDK cannot retrieve locally.
- DThe IAM role associated with the SQS queue has a trust policy that does not include the developer's local workstation IP address under the principal field.
- EThe developer resolved the issue by hardcoding the access key and secret key strings directly as arguments in the SqsClient.builder() constructor.
Answer
The credentials file (~/.aws/credentials) must define the profile without the 'profile' prefix, and the environment variable AWS_PROFILE must be set to the profile name if a default profile is not defined.
The correct options identify valid reasons for the SDK's inability to load credentials. First, in the shared credentials file (~/.aws/credentials), profiles must be declared as [profile_name] (e.g., [dev-profile]) without the 'profile' prefix, which is only used in the configuration file (~/.aws/config). If the prefix is included in the credentials file, the SDK will fail to resolve the profile. Second, if the AWS_PROFILE environment variable is not defined, the default credential provider chain looks for the [default] profile. If no default profile is configured, the chain fails and throws an SdkClientException.
Step-by-Step Solution
Key Concept
AWS SDK credential lookup precedence and configuration syntax rules for local development.