Skip to content

Latest commit

 

History

History

cost-optimization

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

The Cloud Bill Doubled

Level: Intermediate
Estimated time: 1 to 2 weeks
Skills: Cost analysis, FinOps basics, tagging strategy, Terraform, policy enforcement, technical writing
AWS services: AWS Billing and Cost Management, AWS Cost Explorer, AWS Budgets, AWS Cost Anomaly Detection, AWS Organizations, AWS Config, Amazon EC2, Amazon EBS, Amazon S3, Amazon VPC, Amazon CloudWatch Logs, Amazon SNS, AWS Compute Optimizer

Background

ShopNest's finance team sent an escalation to engineering leadership this morning. The AWS bill has roughly doubled over the last two months, and nobody can explain why. Traffic and order volume grew, but nowhere near that much. Finance wants a clear explanation of where the money is going, a list of fixes, and controls so that the next surprise is caught in days, not at the end of the month.

An initial look by the platform lead found several warning signs:

  1. Most resources have no team, env or service tag, so costs cannot be grouped by owner.
  2. A load test environment created last quarter was never torn down, and its instances are much larger than the workload needs.
  3. Several EBS volumes are in the available state, meaning they are not attached to any instance.
  4. Hundreds of EBS snapshots exist, some older than a year, with no retention rule.
  5. Application servers in private subnets download large files from Amazon S3, and that traffic flows through a NAT gateway.
  6. CloudWatch log groups are set to never expire.
  7. No budgets or alerts exist. Finance found out from the invoice.

Nobody is blamed for this. The team grew fast and cost was never part of the definition of done. Your job is to change that.

Your task

Deploy the provided starter scenario into your own sandbox account, investigate it as if it were ShopNest's production account, and deliver two things: a written cost report that explains the waste with evidence, and a Terraform change set that fixes the waste and adds guardrails (tagging enforcement, budgets, anomaly detection, lifecycle and retention rules) so the problem does not return.

Before you start

  • A dedicated sandbox AWS account; the starter stack creates deliberate waste including a NAT gateway.
  • Terraform 1.11 or newer and the AWS CLI. AWS Organizations is needed only if you choose a tag policy or SCP for enforcement.
  • Cost Explorer enabled in the account (it can take up to 24 hours to show data after enabling).
  • Comfortable with: reading a bill, VPC route tables, S3 lifecycle rules.

Suggested milestones

  • Days 1 to 2: deploy the starter/ waste stack, let it run so metrics and cost data exist.
  • Days 3 to 4: tagging standard, default_tags, cost allocation tags activated, enforcement method chosen.
  • Days 5 to 6: budgets, anomaly monitor, SNS; triggered budget alert captured.
  • Days 7 to 9: fixes (S3 endpoint, right-sizing, volumes, snapshots, EIP, lifecycle, log retention) with before and after evidence.
  • Day 10: docs/cost-report.md, docs/tagging-standard.md, evidence, teardown, then open change-request.md.

Milestones are a pacing guide, not extra requirements. Record the date you reach each one; it makes a better story for your README and your interviews.

Current state

You will build the "before" yourself with Terraform so you have something real to analyze. The starter stack must contain:

  • A VPC with public and private subnets and a single NAT gateway. No VPC endpoints.
  • Two or more EC2 instances in the private subnets using an instance type clearly larger than needed for an idle web service, with no tags except Name.
  • At least two EBS volumes created but not attached to any instance.
  • Several EBS snapshots, some tagged as old test data, with no lifecycle rule.
  • An S3 bucket holding sample objects (a few large test files is enough), with no lifecycle policy and versioning enabled.
  • A scheduled job (cron on an instance or a simple script) that repeatedly downloads objects from S3 through the NAT gateway.
  • Several CloudWatch log groups with no retention set.
  • An unassociated Elastic IP address.
  • A mix of tagged and untagged resources so the tag analysis has something to find.

Keep the starter stack in its own Terraform root module (for example starter/) so reviewers can see the "before" separately from your fixes.

Target architecture

The Cloud Bill Doubled architecture

S3 traffic from private subnets goes through a gateway endpoint instead of the NAT gateway. Every resource carries the required tags, and missing tags are caught by policy. Budgets and Cost Anomaly Detection send alerts to an SNS topic that both finance and the platform team receive. Cost Explorer, grouped by cost allocation tags, is the source for the written report.

Requirements

Starter scenario

  • The starter stack is deployed with Terraform only, in one region of your choice.
  • The starter stack must be reproducible: terraform apply from a clean state produces the same waste.
  • Document in the README what each piece of waste is meant to represent.

Tagging policy

  • Define a tagging standard with at least these keys: team, env, service, cost-center. Document allowed values for env.
  • Apply tags to all resources in your Terraform code. Using the AWS provider default_tags block is encouraged.
  • Activate the tag keys as cost allocation tags in the Billing console (or with Terraform if your provider version supports it). Note in your report that activated tags only apply to costs going forward and can take up to 24 hours to appear.
  • Enforce tagging with at least one of: an AWS Organizations tag policy, a service control policy that denies creation of chosen resource types without required tags, or the AWS Config required-tags managed rule. Explain your choice and its limits (for example, which resource types each option covers).

Budgets and anomaly detection

  • Create a monthly cost budget for the account with alerts on actual spend and on forecasted spend.
  • Create at least one budget scoped by a cost allocation tag (for example env = loadtest).
  • Create a Cost Anomaly Detection monitor (AWS services, or a cost allocation tag monitor) with an alert subscription.
  • All alerts go to an SNS topic with an email subscription. The topic policy must allow AWS Budgets and Cost Anomaly Detection to publish.
  • Define budgets and anomaly monitors in Terraform.

Waste fixes

  • Right-size the oversized instances. Use AWS Compute Optimizer or CloudWatch utilization metrics as evidence. If Compute Optimizer has no recommendation yet (EC2 recommendations need at least 30 hours of CloudWatch metrics within the last 14 days), explain your reasoning from the metrics instead.
  • Remove unattached EBS volumes after recording them in the report. Where a volume might matter, snapshot it first and say why.
  • Migrate any gp2 volumes to gp3 and note why.
  • Add a retention policy for EBS snapshots using Amazon Data Lifecycle Manager or AWS Backup. Delete snapshots that fall outside the policy.
  • Release the unassociated Elastic IP. AWS charges for public IPv4 addresses, including idle ones.
  • Add an S3 gateway endpoint to the VPC and associate it with the private route tables. Prove that S3 traffic no longer goes through the NAT gateway.
  • Add S3 lifecycle rules: transition older objects to a cheaper storage class, expire noncurrent versions after a set period, and abort incomplete multipart uploads.
  • Set a retention period on every CloudWatch log group. Document the chosen periods per log type and the reasoning (for example, audit logs kept longer than debug logs).

Cost analysis and report

  • Use Cost Explorer to break down cost by service, by usage type, and by the team and env tags.
  • Include an "untagged" view showing how much spend has no owner.
  • Write the report in docs/cost-report.md. It must contain: a short executive summary for finance, a findings table (resource, problem, evidence, fix, expected effect), the controls added, and open risks.
  • Do not quote prices from memory. Express savings as before and after figures from your own Cost Explorer data, or as a direction (for example "removes hourly NAT data processing for S3 traffic") when your sandbox data is too small to show a real number.

Acceptance criteria

  • The starter stack deploys from a clean state and contains every type of waste listed under Current state.
  • aws ec2 describe-volumes --filters Name=status,Values=available returns no volumes after the fix.
  • The private route tables show a route to the S3 prefix list through the gateway endpoint.
  • VPC Flow Logs or NAT gateway CloudWatch metrics show S3 transfer no longer passing through the NAT gateway after the endpoint is added.
  • Every CloudWatch log group has a retention period (aws logs describe-log-groups shows retentionInDays on all groups).
  • The S3 bucket lifecycle configuration includes a transition rule, a noncurrent version expiration rule and an abort incomplete multipart upload rule.
  • Creating a resource without the required tags is blocked or flagged as noncompliant (screenshot of the denied call or the Config noncompliant result).
  • A budget alert email is received (lower the threshold temporarily to trigger it and record the evidence).
  • A Cost Anomaly Detection monitor and subscription exist and are visible in the console.
  • Cost Explorer screenshots grouped by team and env tags are included in the report.
  • docs/cost-report.md contains the executive summary, findings table and controls section.

Constraints

  • All infrastructure, including budgets, anomaly monitors and Config rules, is managed with Terraform. Console use is allowed only for analysis and for steps Terraform cannot do in your provider version (document these).
  • Use a dedicated sandbox account. Do not run this in an account that hosts real workloads.
  • No long-lived IAM user access keys for Terraform. Use IAM Identity Center or short-lived role credentials.
  • Do not delete data that might be needed without recording it first in the report.
  • Do not invent prices or savings figures. Use your own billing data or describe the effect qualitatively.

Out of scope

  • Savings Plans and Reserved Instance purchases (you may mention them as a recommendation only).
  • Multi-account chargeback and showback dashboards.
  • Kubernetes cost allocation.
  • Building a custom cost dashboard with Amazon QuickSight or Athena.

Mid-sprint change request

In a real job, requirements change while you are building. This project has one change request. It is stored in change-request.md in this folder.

Do not read it until you have finished the main requirements (the last milestone above says when). Opening it early removes the point of the exercise, which is adapting a finished design to a new requirement.

Deliverables

  1. A Git repository with starter/ (the waste scenario) and the fix modules in separate Terraform roots.
  2. docs/cost-report.md: the written cost report for finance.
  3. docs/tagging-standard.md: the tagging policy, allowed values and enforcement method.
  4. An architecture diagram, updated to match what you built.
  5. Evidence folder with screenshots or command output for each acceptance criterion.
  6. A short demo video (5 minutes or less) walking through one finding from evidence to fix.

Definition of done

  • Pull request reviewed by at least one peer or mentor, or a completed self-review committed to the repository.
  • Every acceptance criterion has evidence in the repository.
  • The cost report and tagging standard are written and readable by a non-engineer.
  • All resources are destroyed after the demo, and the teardown is documented.

Cost and cleanup

  • The NAT gateway is billed hourly and per GB processed. It is the main cost in the starter stack, so do not leave it running overnight without reason.
  • EC2 instances, EBS volumes and snapshots, and public IPv4 addresses (including unassociated Elastic IPs) all cost money while they exist.
  • The S3 gateway endpoint has no hourly charge. Interface endpoints do, so do not add interface endpoints you do not need.
  • AWS Config is billed per configuration item recorded and per rule evaluation. Limit the recorder to the resource types you need.
  • Cost Explorer data refreshes about once a day, so your sandbox will show small numbers. That is expected.
  • Run terraform destroy on both the fix and starter roots after the demo, then confirm in the console that no NAT gateway, EIP, volumes or snapshots remain. Document the teardown steps in the README.

Where to read

Official documentation only. If a tool behaves differently from what this brief says, the documentation wins; open an issue so the brief can be corrected.

Resume bullet

Investigated a doubling of AWS spend at an e-commerce company, identified idle and oversized resources, NAT gateway S3 traffic and missing log retention, and delivered Terraform fixes plus tag enforcement, budgets and anomaly alerts that reduced monthly spend by X% and cut untagged spend to Y%. Replace X and Y with your own measured results.

Interview questions to prepare

  1. How would you find which team caused a cost spike if half the resources were untagged?
  2. Why does S3 traffic through a NAT gateway cost more than through a gateway endpoint, and when would you choose an interface endpoint instead?
  3. What is the difference between AWS Budgets and Cost Anomaly Detection, and why use both?
  4. Compare tag policies, SCPs with tag conditions and the AWS Config required-tags rule for tag enforcement.
  5. How do you decide on a CloudWatch Logs retention period for different log types?
  6. How would you right-size an instance safely without causing an outage?

Part of Real DevOps Projects. Build it, push it to your own GitHub, and add it to your resume. Use the evidence template, the demo video guide and the self-review checklist.