An application deployed on Amazon ECS using AWS Fargate starts successfully, but the application code fails with an AccessDeniedException when attempting to read messages from an Amazon SQS queue. The developer verifies that the SQS queue policy does not explicitly deny access. The task definition currently includes an IAM role specified in the executionRoleArn parameter which has the AmazonSQSReadOnlyAccess policy attached. Which of the following actions should the developer take to resolve this authorization failure?
- AModify the trust policy of the ECS task execution role to allow the SQS service principal to assume the role.
- BConfigure an Amazon Cognito Identity Pool to exchange the container's execution credentials for temporary SQS credentials.
- Specify an IAM role with SQS permissions in the taskRoleArn parameter of the task definition.Answer
- DAdd sqs:ReceiveMessage permissions to the IAM role specified in the executionRoleArn parameter of the task definition.
Answer
Specify an IAM role with SQS permissions in the taskRoleArn parameter of the task definition.
The correct answer is to specify the SQS permission policy on the task role (taskRoleArn). The ECS Task Role is designed to grant AWS API permissions to the application code running inside the container. In contrast, the ECS Task Execution Role (executionRoleArn) is used by the ECS container agent for actions like pulling container images from Amazon ECR and sending logs to CloudWatch.
Step-by-Step Solution
Key Concept
ECS Task Role vs Task Execution Role permission boundaries
Estimated Time:1m 30s