A software engineer is configuring an Amazon ECS task definition to deploy a containerized application to AWS Fargate. To simplify log management, the engineer configures the container to use the `awslogs` log driver and sets the `awslogs-create-group` option to `true` in the log configuration. The task definition specifies a custom IAM role for the task execution role. When the engineer attempts to launch the task, the task fails to start and remains in the `STOPPED` state, citing an authorization error related to CloudWatch Logs.
Which configuration change will resolve this deployment issue?
- AAdd the `logs:CreateLogGroup` permission to the custom IAM role assigned as the ECS task role.
- BUpdate the ECS task execution role trust policy to allow the `logs.amazonaws.com` service principal to assume the role.
- Add the `logs:CreateLogGroup` permission to the custom IAM role assigned as the task execution role.Answer
- DConfigure the application code inside the Docker container to use the AWS SDK to verify and create the CloudWatch log group at startup.
Answer
Add the `logs:CreateLogGroup` permission to the custom IAM role assigned as the task execution role.
The correct answer is to add the `logs:CreateLogGroup` permission to the task execution role. When the `awslogs` log driver is configured with `awslogs-create-group` set to `true`, the Amazon ECS container agent automatically attempts to create the specified log group in CloudWatch. Because the agent performs this infrastructure setup action, it requires authorization via the task execution role. The default managed policy `AmazonECSTaskExecutionRolePolicy` only provides permissions to create log streams and put log events, meaning that `logs:CreateLogGroup` must be explicitly added to a custom policy attached to the task execution role.
Step-by-Step Solution
Key Concept
Understanding the division of responsibilities and IAM permissions between the Amazon ECS Task Execution Role and the Task Role when configuring logging.