- Newest
- Most votes
- Most comments
The issue you're experiencing with your ECS scheduled task not writing logs to CloudWatch is likely due to insufficient permissions in the IAM role associated with your task. To resolve this, you need to ensure that the correct permissions are in place for both the task execution and the CloudWatch logging.
Here are the steps you should take:
-
First, make sure your task definition is using the correct task execution role. This role should have the necessary permissions to interact with CloudWatch Logs.
-
The task execution role should have the AmazonECSTaskExecutionRolePolicy attached, which includes the required permissions for CloudWatch Logs. If you're using a custom policy, ensure it includes these permissions:
- logs:CreateLogStream
- logs:PutLogEvents
-
In addition to the task execution role, your container instances (if you're using EC2 launch type) or Fargate tasks need the appropriate permissions. The role should include:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
-
The inline policy you've shown for your EventBridge role is a good start, but it's missing the 'logs:CreateLogGroup' permission. Add this to ensure full functionality.
-
Regarding the "Amazon CloudWatch IAM role" you see in the console, this is typically used for CloudWatch agent configuration on EC2 instances. For ECS tasks, you don't need to configure this separately.
-
Make sure your task definition includes the proper log configuration. In your task definition, you should have a logConfiguration section that specifies the awslogs driver and the appropriate log group and region.
-
If you're using the Fargate launch type, ensure your task definition includes the necessary networkMode and requires compatibilities for Fargate.
After making these changes, your scheduled ECS task should be able to write logs to CloudWatch. If you continue to experience issues, double-check that your task is actually running and that there are no errors in the task execution itself.
Sources
Send Amazon ECS logs to CloudWatch - Amazon Elastic Container Service
Access to CloudWatch Logs - AWS Lambda
Troubleshoot permission errors for an instance on CloudWatch | AWS re:Post
answered 2 years ago
Relevant content
asked 4 years ago
asked 3 years ago
- AWS OFFICIALUpdated 2 years ago
