A developer is deploying a containerized application to Amazon ECS on Amazon EC2. The application uses the AWS SDK to write data to an Amazon DynamoDB table. During local testing, the developer used a shared credentials file located at `~/.aws/credentials` inside the container. After deployment, the application fails to authenticate with DynamoDB because the SDK is still using the expired local credentials instead of the assigned ECS Task Role.
Which two actions should the developer take to resolve this issue and ensure the application correctly and securely utilizes IAM roles for authentication? (Select TWO.)
- Remove the shared credentials file from the container image.Answer
- Ensure the ECS task is configured with a Task Role that has the required DynamoDB permissions, allowing the ECS agent to inject the container credentials environment variable.Answer
- CHardcode the AWS access key and secret access key in the SDK client constructor.
- DModify the EC2 instance profile's trust policy to allow the ECS task execution role to assume it.
- ESave the AWS credentials in AWS Systems Manager Parameter Store and retrieve them using the SDK at startup.
Answer
Remove the shared credentials file from the container image, and ensure the ECS task is configured with a Task Role that has the required DynamoDB permissions, allowing the ECS agent to inject the container credentials environment variable.
The AWS SDK credential provider chain prioritizes shared credentials files over ECS container credentials. Removing the local shared credentials file allows the chain to fall back to the container credentials provider. Ensuring that the task has an ECS Task Role configured allows the ECS agent to set the necessary container credentials environment variable, enabling the SDK to obtain temporary IAM credentials.
Step-by-Step Solution
Key Concept
AWS SDK Credential Provider Chain Precedence
Estimated Time:2m 0s