1.Centralized Logging, Not Instance Files
A log file on a server only exists while that server does. On AWS, instances are replaced by an Auto Scaling group, containers are stopped and rescheduled, and Lambda execution environments disappear — so the logs of the failure that caused the replacement disappear with it. Centralized logging means the application writes to standard output or to an agent, and something else ships those events off the host as they are produced.
Key features
- An unhealthy instance is terminated and replaced, so the local logs explaining why it was unhealthy are destroyed at exactly the moment they become interesting
- A container writing to stdout/stderr has its output collected by the task's log driver (`awslogs` for CloudWatch Logs) with no file management in the container
- Lambda writes to CloudWatch Logs by default; the execution environment is not something you can log into afterwards
- A log group collects streams from every instance or task of a service, so a query can span the whole fleet instead of one host
- Logging to a file and shipping it with an agent is still valid — the CloudWatch agent does this — but the file is a buffer, not the record
- SSH-ing to a host to read logs does not scale past a handful of servers, and stops working entirely once instances are ephemeral
- Local files
- Destroyed when the instance is replaced
- Readable only by someone who can log in
- One host at a time, no cross-fleet query
- Fills the disk, which itself causes outages
- Centralized
- Survives the instance that produced it
- Read through IAM, not SSH
- One query across every task in the service
- Retention and cost are configured, not accidental
Signature
app → stdout / agent → log group (per service) → query across the fleet
Compute on AWS is replaced automatically, so logs that live on it are destroyed by normal operation. Write to stdout or to an agent, ship every event off the host as it is produced, and read logs through a log group query rather than by logging into a machine.