Ravindra BagaleCourses & study guides मराठी

Chapter 89: Amazon ECS for DevOps

DevOps

89.8 Logs to CloudWatch

Story. When pay-api returned 500s, the on-call in Mumbai had no SSH box on Fargate. The task definition used the awslogs driver. Lines landed in a CloudWatch Logs group /ecs/pay-api. A metric filter watched for ERROR and paged Slack through a harmless webhook pattern (no real secrets in the lesson). Logs are the flashlight you keep when there is no host to enter.

Container stdout goes through awslogs to a CloudWatch log group you can search and alarm on.
Container stdout goes through awslogs to a CloudWatch log group you can search and alarm on.

Why

Without central logs, Fargate incidents become guesswork. stdout/stderr must leave the task.

What

  • awslogs log driver — Sends container logs to CloudWatch Logs.
  • Log group / stream — Group per app; stream often per task/container.
  • Execution role permission — Execution role needs rights to create streams and put events.
  • CloudWatch Logs Insights — Query language to search across streams.
  • Retention — Set retention so log storage cost stays bounded (check current pricing).

How

  1. Create a log group (or let first start create it if your IaC allows).
  2. Add logConfiguration with awslogs on each container in the task definition.
  3. Confirm the execution role can write logs.
  4. Practice one Insights query before the incident.

Example 1: Log configuration block

"logConfiguration": {
  "logDriver": "awslogs",
  "options": {
    "awslogs-group": "/ecs/pay-api",
    "awslogs-region": "ap-south-1",
    "awslogs-stream-prefix": "pay"
  }
}

What it shows: stdout from the container goes to /ecs/pay-api in ap-south-1 with a stream prefix.

Example 2: Tail recent events (shape)

aws logs tail /ecs/pay-api --since 10m --region ap-south-1

Output

2026-11-03T08:01:12 PAY ok path=/healthz
2026-11-03T08:01:40 PAY ERROR path=/charge request_id=abc-1

What it shows: Recent lines from the group. Use request ids in your app logs so one failing charge is easy to find.

Ravindra Bagale's Tip

Set log retention on day one. Infinite retention is an approximate bill you notice at month end.

Quick quiz

Q1. Which log driver sends ECS logs to CloudWatch?

awslogs.

Q2. Which IAM role usually needs log write permission?

The task execution role.

Q3. Why set retention?

To control CloudWatch Logs storage cost over time.

Did you understand? Let us try it once more.