Skip to content

Cost switches

2 min read · main part only; folded sections are optional

After this you can answer: How do you turn the environment off to save money, and what stays on?

flowchart TB
D["dataEnabled<br/>RDS, Valkey, their secrets"] --> C["computeEnabled<br/>cluster, services, Lambdas, logs"]
C --> E["entryEnabled<br/>ALB, listeners, web service"]
A["always on: network, queues, topics,<br/>tables, bucket, ECR, IAM, alarms, budget"]
  1. Edit the committed file. infra/Pulumi.dev.yaml holds dataEnabled, computeEnabled, entryEnabled, cdnEnabled and domainName.
  2. Commit, push, approve. CD’s deploy job reads the committed switches. With compute off it only applies the config: no migration, no image change.
  3. Dependencies are enforced. Compute needs data; entry needs both. The infrastructure code stops with a clear error otherwise. So turn on data → compute → entry, and off in reverse (or all at once).
  4. The deployed tag stays in SSM, so the next “on” starts the same version again.
Switch offRemovesKeep in mind
entryEnabledALB, listeners, target groups, web serviceNo public URL; the smoke test is skipped
computeEnabledcluster, task definitions, services, both Lambdas, log groupsMessages wait in the queues, for up to 4 days
dataEnabledRDS Postgres, Valkey, their secretsDeletes the data: dev keeps no final snapshot

Always on, because they are free or billed per request: the network and security groups, ECR, SSM, the CI/CD roles, SNS, SQS, both DynamoDB tables, the assets bucket, SES, the certificate, two alarms, the dashboard and the budget. Issued tickets survive an “off”, and waiting messages too, for the queue’s 4 days.

The budget minitickets-dev-monthly-cost has a limit of 20 USD per month. It emails at 25%, 50% and 100% of actual spend, and when the forecast passes 100%. includeCredit is false, so it shows the real cost even while credits pay the bill. It only warns; it never stops anything.

From → toWhat happensWhat allows it
Monthly cost budget → AWS account and regionwatches the whole account's monthly cost
  • metric COST budget 20 USD per month; emails at 25%, 50%, 100% actual and 100% forecastcreateBudget
See stage 0 on the map: the account and its budget →

Billing and Cost Management → Budgets → minitickets-dev-monthly-cost; Cost Explorer, grouped by service.

SymptomCauseWhere to look
The 50% alert arrives in the first weekAll switches stayed on: RDS, the ALB and tasks billed every hourCost Explorer by service
The bill passed 20 USD and nobody got an emailalertEmail is wrong, or the mail went to spamBudgets → alerts
A switch change is undoneIt was applied locally, not committedgit log -- infra/Pulumi.dev.yaml
Why delete the database instead of stopping it?

A stopped RDS instance still bills its storage, and AWS starts it again after seven days. Dev data is seed data, so deleting it is acceptable here; production would keep snapshots.

Why are the switches in git and not a script?

One committed source of truth: CD applies exactly what is reviewed, and the history shows who turned what on.

Why does a budget not stop spending?

AWS Budgets can run actions, but stopping resources automatically could break things at a bad moment. We chose a warning and a person.

Advanced: Details: cdnEnabled

cdnEnabled chooses CloudFront mode or ALB-only mode (today false: ALB-only). Change it only while entry is off; the listener and security group rules differ between the two modes.

Answer these without scrolling up. If one feels hard, reread that section.

  1. Which three switches turn billed layers off?
  2. How do you turn the environment off, step by step?
  3. What does switching data off delete?
  4. Name four things that stay on, and why.
  5. What does the budget do at 50%?

Redraw it from memory: dataEnabled → computeEnabled → entryEnabled (on in this order, off in reverse); always on: network, queues, tables, bucket, IAM, alarms, budget

Try this: on the map, move the stage slider to 0 and select the monthly cost budget

Read this book online: https://book.theversehub.in/