A developer has deployed a containerized Node.js application to Amazon ECS on AWS Fargate. The application uses the AWS SDK for JavaScript (v3) to read from an Amazon DynamoDB table. The ECS task is configured with an IAM Task Role that has the required DynamoDB permissions. However, the application fails to query the table, and the developer receives an authentication error from DynamoDB. During debugging, the developer notices that the container definition still includes the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` set to mock values used during local testing.
Which of the following explains why the application is failing to access DynamoDB, and what is the correct resolution?
- AThe application fails because permissions to access DynamoDB must be attached to the ECS Task Execution Role rather than the ECS Task Role. To resolve this, attach the required IAM policy to the Task Execution Role and remove the environment variables.
- BThe default credential provider chain does not automatically resolve ECS container credentials unless explicitly configured in code. To resolve this, modify the SDK client initialization to instantiate the DynamoDB client using the container credentials provider class.
- The AWS SDK default credential provider chain evaluates environment variables before checking for ECS container credentials. The SDK signed requests using the mock environment variables, leading to authentication failures. To resolve this, remove the mock environment variables from the container definition.Answer
- DThe ECS Task Role is missing a custom policy mapping the environment variables to the container agent's IAM role. To resolve this, update the IAM trust policy to trust the ECS service principal and set the container's environment variables to read-only.
Answer
The AWS SDK default credential provider chain evaluates environment variables before checking for ECS container credentials. The SDK signed requests using the mock environment variables, leading to authentication failures. To resolve this, remove the mock environment variables from the container definition.
The correct answer explains that the AWS SDK's default credential provider chain searches environment variables before any other credential sources. If mock or placeholder credentials exist in the environment, the SDK selects them immediately and attempts to use them to sign requests, resulting in authentication failures. Removing the mock variables allows the default provider chain to evaluate subsequent options and retrieve the ECS Task Role credentials.
Step-by-Step Solution
Key Concept
AWS SDK default credential provider chain precedence