A company is deploying a secure microservice to Amazon ECS using the AWS Fargate launch type. The application code inside the container must pull messages from an Amazon SQS queue and write processed records to an Amazon DynamoDB table. Additionally, when the container is initialized, the Amazon ECS agent must retrieve database credentials from AWS Secrets Manager using the container definition secrets parameter and inject them as environment variables. The secret is encrypted using an AWS KMS customer managed key (CMK). During deployment, the tasks fail to transition to the RUNNING state, and the developer receives an error indicating that the container helper was unable to retrieve the Secrets Manager secret. How should the developer configure the IAM roles to resolve this issue and adhere to the principle of least privilege?
- Associate an IAM policy granting secretsmanager:GetSecretValue and kms:Decrypt permissions to the ECS Task Execution Role, and associate a separate IAM policy granting SQS and DynamoDB permissions to the ECS Task Role.Answer
- BAssociate an IAM policy granting secretsmanager:GetSecretValue, kms:Decrypt, SQS, and DynamoDB permissions to the ECS Task Role, and leave the ECS Task Execution Role with the default AmazonECSTaskExecutionRolePolicy.
- CAssociate an IAM policy granting secretsmanager:GetSecretValue and kms:Decrypt permissions to the ECS Task Execution Role, and update the trust policy of the ECS Task Execution Role to allow the service principal ecs.amazonaws.com to assume the role.
- DAssociate an IAM policy granting secretsmanager:GetSecretValue and kms:Decrypt permissions to the ECS Task Execution Role, and configure the application code to initialize SDK clients by hardcoding temporary IAM user access keys.