We begin Chapter 24: Observability, one of the skills that most distinguishes a professional who knows how to operate in production. Having an application running is not enough: you need to know what's happening inside it at all times. Is it going well? Are there errors? Is it overloaded? That's what observability is for, and in AWS the central tool is CloudWatch. Let's start with its three pillars: logs, metrics, and alarms.

The Problem: Operating Blind

Imagine you have your application deployed in production. Users are using it. And suddenly... it starts to slow down, or some users report errors. Without observability, you are blind:

  • How many errors are occurring? You don't know.
  • Is the server overloaded with CPU? No idea.
  • What exactly happened when it failed? There's no trace.
  • When did the problem start? Impossible to know.

Operating like this is like driving with your eyes closed. Observability is the dashboard instruments of your application: they tell you what's happening, so you can react.

What is CloudWatch

CloudWatch is the AWS observability service: it collects and displays information about the operation of your resources and applications. It's where you look to see if everything is going well. It has several components; in this subchapter we look at the three fundamental ones.

Pillar 1: Logs

Logs are the text messages that your applications and services write about what they are doing. They are your application's journal:

[10:32:01] User 4521 logged in
[10:32:05] Processing order #8890
[10:32:06] ERROR: could not connect to the database
[10:32:07] Retrying connection...

CloudWatch Logs collects and stores these messages centrally. Instead of having logs scattered on each server (and losing them if the server shuts down), they all go to CloudWatch, where you can search, filter, and query them.

Analogy: logs are like the ship's logbook: the captain writes down everything that happens ("10:00 set sail", "12:00 storm in sight", "12:30 leak repaired"). If something goes wrong, you check the logbook to understand what happened and when. CloudWatch Logs is the place where all those logbooks are kept together, ready to consult.

Logs are your first tool when something fails: you go to the logs from the time of the failure and read what happened.

Pillar 2: Metrics

Metrics are numerical values measured over time: CPU usage, amount of memory, number of requests per second, errors per minute... While logs are text ("what happened"), metrics are numbers ("how much"):

Metric "CPU Usage" of the server throughout the day:
   10:00  →  20 %
   11:00  →  35 %
   12:00  →  85 %   ← peak!
   13:00  →  40 %

CloudWatch automatically collects many metrics from your resources (EC2 CPU, ALB requests, Lambda invocations...) and you can send your own (business metrics, like "orders completed per minute"). With metrics you see trends and detect when something is out of the ordinary.

Analogy: metrics are like the dashboard indicators in a car: speed, RPM, engine temperature, fuel level. They are numbers you glance at to know if everything is okay. If the temperature needle rises too much, you know there's a problem before the engine breaks down.

Pillar 3: Alarms

Here's the piece that makes observability proactive. You can't be watching metrics 24 hours a day. An alarm monitors a metric for you and automatically notifies you when it crosses a threshold you define:

Alarm: "if CPU usage exceeds 80% for 5 minutes → NOTIFY"
Alarm: "if errors exceed 10 per minute → NOTIFY"
Alarm: "if the database runs out of space → NOTIFY"

When an alarm is triggered, it can notify you (by email, Slack, etc., using SNS, remember subchapter 15.2) or even trigger an automatic action (like adding more servers with an Auto Scaling Group, remember subchapter 13.3).

Analogy: an alarm is like the red warning light on the dashboard that comes on when the engine temperature is dangerous, accompanied by a beep. You don't have to constantly watch the needle: the car alerts you when something important needs your attention.

How the Three Work Together

The three pillars work as a team so you operate with your eyes open:

METRICS  → tell you WHAT is happening (numbers, trends)
ALARMS   → ALERT you when a metric goes out of range
LOGS     → tell you WHY it happened (the details, for investigation)

The typical incident flow: an alarm goes off ("high errors!"), you look at the metrics to see the scope and when it started, and you go to the logs from that moment to understand the exact cause and fix it.

Real-world example: an online store has an alarm on the "HTTP 500 errors" metric. On a Sunday night, a change introduces a bug and errors spike. The alarm goes off and notifies the on-call team via Slack in one minute. The engineer checks the metrics: errors started right after the last deployment, at 22:14. They go to the logs from 22:14 and see: "ERROR: 'price' field null in cart". In 10 minutes they identify and revert the change. Without observability, they would have found out the next morning from customer complaints and lost sales.

What You Should Remember

  • Operating without observability is driving with your eyes closed; you need to know what's happening inside your application at all times.
  • CloudWatch is AWS's observability service, with three fundamental pillars:
  • Logs: the text messages your apps write ("what happened"), collected and queryable centrally. They are the logbook.
  • Metrics: numerical values over time ("how much": CPU, requests, errors...). They are the dashboard indicators; they reveal trends.
  • Alarms: monitor a metric and automatically alert you (or trigger actions) when it crosses a threshold. They are the red warning light that alerts you without having to look.
  • They work as a team: alarms alert, metrics show the scope, logs explain the cause.

In the next subchapter, we'll see how to bring all these metrics together in visual panels with CloudWatch Dashboards.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved