A developer is deploying a Node.js application to Amazon ECS on AWS Fargate. The application needs to read messages from an Amazon SQS queue. The developer has created an IAM Task Role with the necessary permissions and associated it with the ECS Task. However, when the application runs in ECS, it throws a credentials error stating that it cannot load credentials. The developer discovers that the application task definition has residual `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables set to empty values, which were used during local Docker container testing.
Which of the following actions should the developer take to resolve this issue and follow AWS security best practices? (Select TWO.)
- Remove the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables from the ECS task definition.Answer
- Verify that the application's SDK client initialization relies on the default credential provider chain.Answer
- CAttach the SQS permissions to the ECS Task Execution Role instead of the ECS Task Role.
- DConfigure the ECS container to query the EC2 Instance Metadata Service (IMDSv2) to retrieve credentials.
- EPackage the developer's local AWS credentials file inside the Docker image under the ~/.aws/credentials path.
Answer
The developer should remove the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables from the task definition, and ensure the SDK client utilizes the default credential provider chain.
Removing the empty environment variables from the task definition allows the SDK default credentials provider chain to proceed past the environment variable stage. Because the application is running in an ECS task, the SDK then queries the container credentials endpoint to assume the IAM Task Role. The client initialization must also rely on the default provider chain, which automatically supports this resolution.
Step-by-Step Solution
Key Concept
Default Credential Provider Chain Precedence
Estimated Time:1m 30s