A developer is testing a Java application locally that uses the AWS SDK for Java v2 to retrieve objects from an Amazon S3 bucket. The application initializes the S3 client using S3Client.create(). When running the application locally, it fails with a software.amazon.awssdk.core.exception.SdkClientException stating that it is unable to load credentials from any of the providers in the default chain. The developer has configured the credentials in the local ~/.aws/credentials file under a profile named developer-local.
Which two actions should the developer take to resolve this credentials loading issue? (Select two.)
- Set the environment variable AWS_PROFILE to developer-local in the local command shell before running the application.Answer
- Define the JVM system property -Daws.profile=developer-local when launching the Java application.Answer
- CModify the Java application code to initialize the S3Client by hardcoding the credentials using StaticCredentialsProvider.
- DModify the IAM Role trust policy associated with the S3 bucket to trust the developer workstation's local IP address.
- EStore the credentials in AWS Systems Manager Parameter Store as a Standard String parameter and fetch them at application startup.
Answer
Setting the AWS_PROFILE environment variable to developer-local or defining the JVM system property -Daws.profile=developer-local directs the AWS SDK for Java v2 to use the credentials associated with that profile from the credentials file.
The correct options are setting the environment variable AWS_PROFILE to developer-local or using the JVM system property -Daws.profile=developer-local. The DefaultCredentialsProvider in the AWS SDK for Java v2 automatically checks the system property and the environment variable to determine which profile to use when loading credentials from the shared credentials file.
Step-by-Step Solution
Key Concept
AWS SDK Credential Provider Chain Resolution for Local Development Profiles