We begin Chapter 25: Cost Optimization, a topic that is critical in the cloud and that many discover the hard way: an unexpected bill. In the cloud, you pay for what you use (remember the pay-as-you-go model from subchapter 1.3), which is great... but it also means costs can skyrocket if you don't keep them in check. The good news is that AWS offers tools to see, understand, and control what you spend. We'll start with the two fundamental ones: Cost Explorer (to see) and Budgets (to alert).

The problem: the surprise bill

In the cloud, you don't buy servers in advance; you pay for usage, hour by hour. This is flexible, but dangerous if you don't keep an eye on things:

  • You leave a large server running unused → it keeps costing you.
  • A service scales more than expected → the bill goes up.
  • You forget to delete resources from a test → they keep charging you silently.
  • An error or attack spikes consumption → huge bill.

The beginner's terror: real stories of people who left something misconfigured and received a bill for thousands of euros at the end of the month. Not out of bad luck, but for not monitoring costs. This is easily avoided with the tools we'll see.

The key is not to operate blindly with money, just as you wouldn't operate blindly with performance (Chapter 24). You need visibility and alerts.

Tool 1: Cost Explorer (see and understand spending)

AWS Cost Explorer is the tool to visualize and analyze what you spend on AWS. It shows your costs in graphs and lets you break them down in many ways to understand where the money is going:

   Monthly cost by service:
   EC2 (servers)      ████████████  450 €
   RDS (databases)    ██████        220 €
   S3 (storage)       ██             80 €
   Others             █              50 €
   ──────────────────────────────────────
   TOTAL                            800 €

With Cost Explorer you can break down spending by service (what costs me the most?), by tag (how much does each project or team spend? — remember the tags from subchapter 6.x), by region, and by time (how is my spending evolving? Is it going up?).

Analogy: Cost Explorer is like the bank app that categorizes your expenses: it shows you how much you spent on food, transport, entertainment... over the months. Without that app, you'd only see the total at the end and wouldn't know where your money went. With it, you understand your expenses and spot where to cut back.

Cost Explorer is your starting point: before optimizing, you need to know what you're spending on.

Tool 2: Budgets (budgets with alerts)

Seeing your spending is good, but it's reactive (you look at what you've already spent). To be proactive and avoid surprises, you use AWS Budgets: you set a budget (a spending limit) and AWS automatically notifies you when you approach or exceed it.

Budget: "I don't want to spend more than €1,000 a month"
   → when reaching 80% (€800):  ⚠️ ALERT "you're at 80%"
   → when reaching 100% (€1,000): 🚨 ALERT "you've reached the limit"
   → if you're projected to exceed it:  📈 ALERT "at this rate you'll go over"

Alerts arrive by email, Slack, etc. (just like CloudWatch alarms from subchapter 24.1, but for money instead of performance). This makes the surprise bill impossible: you find out while it's happening, not at the end of the month.

Analogy: Budgets is like setting an alert on your bank account that notifies you when you're about to spend more than you planned this month. Instead of discovering you're overdrawn when it's too late, you get a timely alert to stop. It gives you control before the problem grows.

How they work together

COST EXPLORER  → what am I spending on? (understand, analyze)  [reactive]
BUDGETS        → alert me if I go over the limit  (control)     [proactive]

Cost Explorer gives you knowledge (where the money goes) and Budgets gives you control (alerts so you don't overspend). Together, they are the foundation of cost management.

Real-world example: a startup sets up, as soon as they start on AWS, a Budget of €500 per month with alerts at 50%, 80%, and 100%. One month, a developer accidentally leaves a very large instance running over a weekend. On Monday, the team receives the Budgets alert: "you're at 80% of the budget and it's only the 10th." They investigate with Cost Explorer, see that EC2 spending has spiked, find the forgotten instance, and shut it down. They avoided a massive bill thanks to a timely alert. Without Budgets, they would have discovered it at the end of the month, with the damage already done.

Basic cost best practices

  • Set up a Budget from day one, even if it's small. It's the first thing anyone starting on AWS should do.
  • Tag your resources (by project, team, environment) to break down costs in Cost Explorer.
  • Review Cost Explorer regularly to spot trends and unusual spending.
  • Delete what you don't use (remember terraform destroy for temporary environments, subchapter 11.4).

What you should remember

  • In the cloud you pay for usage, so costs can skyrocket if you don't monitor them; the dreaded surprise bill is easily avoided with the right tools.
  • Cost Explorer visualizes and analyzes your spending: it breaks it down by service, tag, region, and time to understand where the money goes. Like the bank app that categorizes your expenses. It's reactive (see what you've spent).
  • Budgets lets you set budgets (limits) and automatically alerts you when you approach or exceed them (even if you're projected to go over). Like a bank alert. It's proactive (control before you overspend).
  • Together: Cost Explorer provides knowledge, Budgets provides control. They are the foundation of cost management.
  • Best practices: set up a Budget from day one, tag resources, review Cost Explorer often, and delete what you don't use.

In the next subchapter, we'll look at tools that go beyond just showing spending: they actively recommend how to save and improve, with Trusted Advisor and Compute Optimizer.

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