Question

Difficulty: EasyTroubleshooting Local Development and AWS Credentials

A developer is running a local Node.js application that uses the AWS SDK for JavaScript (v3) to read data from an Amazon DynamoDB table. The local machine has multiple AWS profiles defined in the `~/.aws/credentials` file. When executing the application, it fails with an `AccessDeniedException` because it attempts to use the default profile instead of a specific profile named `development-admin`. Which of the following actions can the developer take to resolve this issue? (Select TWO.)

  1. Set the `AWS_PROFILE` environment variable to `development-admin` in the local terminal before executing the application.Answer
  2. Import the `fromIni` credential provider from the SDK and use it to explicitly instantiate the DynamoDB client with the `development-admin` profile.Answer
  3. C
    Hardcode the AWS Access Key ID and Secret Access Key from the `development-admin` profile directly into the application code during client initialization.
  4. D
    Store the access keys in AWS Systems Manager Parameter Store and retrieve them dynamically without configuring any local credentials.
  5. E
    Update the IAM trust policy of the DynamoDB service role to allow access from local development IP addresses without credentials.

Answer

Configure the local application to use the correct profile by setting the AWS_PROFILE environment variable or by explicitly loading the profile using the fromIni credential provider in the application code.
Setting the AWS_PROFILE environment variable forces the AWS SDK to look for the specified profile inside the shared credentials file. Alternatively, programmatically loading the profile via the fromIni credential provider configures the client to explicitly request credentials matching the development-admin profile.

Step-by-Step Solution

1
Analyze how the AWS SDK for JavaScript resolves local credentials.
Identify that the SDK uses the Default Credential Provider Chain, which looks for the AWS_PROFILE environment variable before falling back to the default profile in the credentials file.
Understanding credential precedence is key to routing local requests to the correct IAM profile.
2
Configure the execution environment using a named profile.
Setting the AWS_PROFILE environment variable instructs the SDK to use the development-admin profile from the shared configuration, resolving the AccessDeniedException.
Environment variables are evaluated early in the provider chain and require no code changes.
3
Implement code-based profile selection as an alternative.
Use the fromIni provider to programmatically select the development-admin profile from the credentials file.
This guarantees that the application consistently targets the correct profile, regardless of the developer's terminal environment variables.

Key Concept

AWS SDK Credential Provider Chain and Named Profiles
Estimated Time:1m 0s
Rate this question