Cost management: Budgets, Cost Explorer, Savings Plans

Of all the reports, the cloud bill is the one every manager actually reads. AWS cost optimization is something you do as a routine and not as a one-off project: you see where the money goes, get warned before a budget is blown and clear out the waste, and only after that do you commit to discounts like Savings Plans.

You’ll break down your month-to-date cost by service and by the course tag, create a tag-based budget with email alerts and check what Savings Plans would suggest. You’ll also write Find-Waste.ps1, a script that finds the leftovers quietly costing you money, and then fix a date bug that breaks cost scripts on the 1st of every month.

TimeYou needBy the end you can
45 minutesYou need Lesson 4 done (with the course tag activated for cost allocation), your laptop signed in as saat-admin and an email address for budget alerts. It costs about USD 0.10, since Cost Explorer API calls are USD 0.01 each and an idle Elastic IP sits around for a few minutes.Query Cost Explorer by service and by tag, create budgets on actual and forecasted spend and read Savings Plans recommendations. Then find idle resources with a script and learn to avoid the usual cost-reporting mistakes.

What it is, in one line

AWS cost optimization means continuously matching what you pay for with what you use, through visibility (Cost Explorer), alerts (Budgets), cleanup and commitment discounts.

In Simple Words

The household electricity bill

When the electricity bill suddenly jumps, a family first works out what used the power, whether it was the AC, the geyser or the old fridge. That’s Cost Explorer.

Next they agree that “if we hit 80 percent of our usual bill by the 20th, we sit down and talk about it”, which is a budget alert.

Then they switch off fans in empty rooms and replace the old fridge, which is removing waste and rightsizing. Only once that’s done does a yearly plan with the electricity company make sense, and that plan is your Savings Plan.

Engineer's View

How AWS cost tools work

Cost Explorer shows cost and usage by service, account, Region, usage type and cost allocation tag, with up to 13 months of history plus forecasts, and its API (ce) charges USD 0.01 per request. Tags show up in billing only after you activate them as cost allocation tags, and only for costs from that point onwards.

Time periods take an inclusive start date and an exclusive end date.

AWS Budgets tracks cost, usage, or Savings Plans and Reserved Instance coverage against a limit. It alerts on actual or forecasted values by email, SNS or chat and can take optional actions such as applying an IAM policy or SCP or stopping instances. Cost Anomaly Detection uses machine learning to flag unusual spend, and many accounts already have it on with a default monitor.

Savings Plans give you up to about 66 percent off (Compute), or more (EC2 Instance), in return for a one- or three-year commitment in USD per hour. Rightsize before you commit and only cover the steady base. Compute Optimizer recommends instance sizes based on CloudWatch data.

The usual waste is unassociated Elastic IPs (all public IPv4 is charged), unattached volumes, old snapshots, idle NAT gateways and load balancers, and log groups with no retention set.

How it works, step by step

This is the routine you’ll practise:

AWS cost optimization routine: see it, get warned, remove waste, rightsize then commit

1See it

Group cost by service and by tag. You can only answer “which team or project spent this?” if resources are tagged and the tag has been activated.

2Get warned

A budget on forecasted spend warns you mid-month while there’s still time to act, and a budget on actual spend confirms what happened.

3Remove waste, then commit

Most first reviews turn up the same leaks:

Where AWS money leaks: idle Elastic IPs, unattached EBS, NAT and data transfer, over-sized instances

If you commit to Savings Plans before cleaning up, you’re locked into paying for waste for one or three years, so clean up and rightsize first.

✅ Checkpoint: You can explain cost allocation tags, actual versus forecasted budget alerts, why Savings Plans come last and where waste usually comes from.

Hands-on lab: AWS cost optimization from the CLI

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Sign in and set your alert email:

cd C:\aws-lab
aws login --profile saat-admin
$env:AWS_PROFILE = 'saat-admin'
$acct = aws sts get-caller-identity --query Account --output text
$email = 'you@example.com'

1See month-to-date cost by service and tag

Paste this whole block (two Cost Explorer calls, USD 0.02):

$today = Get-Date
if ($today.Day -eq 1) { $start = $today.AddMonths(-1).ToString('yyyy-MM-01') } else { $start = $today.ToString('yyyy-MM-01') }
$end = $today.ToString('yyyy-MM-dd')
$r = aws ce get-cost-and-usage --time-period "Start=$start,End=$end" --granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE --output json | ConvertFrom-Json
$byService = $r.ResultsByTime[0].Groups | ForEach-Object { [pscustomobject]@{ Service = $_.Keys[0]; USD = [math]::Round([double]$_.Metrics.UnblendedCost.Amount, 2) } } | Sort-Object USD -Descending
$byService | Select-Object -First 4 | Format-Table -AutoSize
$t = aws ce get-cost-and-usage --time-period "Start=$start,End=$end" --granularity MONTHLY --metrics UnblendedCost --group-by Type=TAG,Key=course --output json | ConvertFrom-Json
$t.ResultsByTime[0].Groups | ForEach-Object { "{0,-28} {1:N2}" -f $_.Keys[0], [double]$_.Metrics.UnblendedCost.Amount }

You should see something like this (your numbers will differ):

Service                                  USD
-------                                  ---
Amazon Elastic Compute Cloud - Compute   1.84
Amazon Virtual Private Cloud             1.12
Amazon Simple Storage Service            0.21
AWS Key Management Service               0.08
course$                      0.31
course$saatvedha-aws         3.42

course$ is untagged spend, such as tax lines, some data transfer and resources created without the tag. In a real company a large untagged share is the first thing to fix, because nobody can own it. The VPC cost is mostly the interface endpoints you create in the labs.

AWS cost optimization lab output: month-to-date cost by service and tag budget spend
Month-to-date cost by service and the tag budget. Something like this.

2Budget the course tag

Paste this whole block. There’s nothing to confirm, because budget emails don’t need a subscription:

@'
{
  "BudgetName": "saat-course-tag",
  "BudgetLimit": { "Amount": "5", "Unit": "USD" },
  "TimeUnit": "MONTHLY",
  "BudgetType": "COST",
  "CostFilters": { "TagKeyValue": [ "user:course$saatvedha-aws" ] }
}
'@ | Set-Content budget.json
@'
[
  { "Notification": { "NotificationType": "ACTUAL", "ComparisonOperator": "GREATER_THAN", "Threshold": 80, "ThresholdType": "PERCENTAGE" },
    "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "EMAIL_ADDRESS" } ] },
  { "Notification": { "NotificationType": "FORECASTED", "ComparisonOperator": "GREATER_THAN", "Threshold": 100, "ThresholdType": "PERCENTAGE" },
    "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "EMAIL_ADDRESS" } ] }
]
'@ -replace 'EMAIL_ADDRESS', $email | Set-Content budget-notifications.json
aws budgets create-budget --account-id $acct --budget file://budget.json --notifications-with-subscribers file://budget-notifications.json
Start-Sleep 30
aws budgets describe-budget --account-id $acct --budget-name saat-course-tag --query "Budget.[BudgetLimit.Amount,CalculatedSpend.ActualSpend.Amount]" --output text

You should see something like this (spend can take a few hours to appear for a new budget):

5.0     3.42

An email arrives when course-tagged spend passes 80 percent of USD 5, and earlier than that if AWS forecasts you’ll go past USD 5 by the end of the month. Look at the filter format, user:course$saatvedha-aws, which uses the user: prefix for your own tags.

3Ask about Savings Plans

Paste this whole block:

aws ce get-savings-plans-purchase-recommendation --savings-plans-type COMPUTE_SP --term-in-years ONE_YEAR --payment-option NO_UPFRONT --lookback-period-in-days THIRTY_DAYS --query 'length(SavingsPlansPurchaseRecommendation.SavingsPlansPurchaseRecommendationDetails || `[]`)'

You should see this in a lab account:

0

There’s no recommendation, because nothing in a lab account runs steadily. In a company running 40 servers all month, the same call would suggest an hourly commitment and the expected saving. Even then, only buy enough to cover the floor of your usage, and do it after rightsizing.

4Write a waste finder

Paste this whole block, which saves Find-Waste.ps1 and runs it:

@'
param([string]$Region = 'ap-south-1')
# Rough Mumbai list prices; check the pricing pages for your Region.
$gp3PerGb = 0.0912; $snapPerGb = 0.05; $ipv4PerMonth = 3.65
$rows = @()
foreach ($l in @(aws ec2 describe-volumes --region $Region --filters Name=status,Values=available --query "Volumes[].[VolumeId,Size,VolumeType,AvailabilityZone]" --output text)) {
  if (-not $l) { continue }
  $id, $size, $type, $az = $l -split "`t"
  $rows += [pscustomobject]@{ Type = 'EBSVolume'; Id = $id; Detail = "$size GiB $type, $az"; EstUsdPerMonth = [math]::Round([double]$size * $gp3PerGb, 2) }
}
foreach ($l in @(aws ec2 describe-addresses --region $Region --query "Addresses[?AssociationId==null].[AllocationId,PublicIp]" --output text)) {
  if (-not $l) { continue }
  $id, $ip = $l -split "`t"
  $rows += [pscustomobject]@{ Type = 'ElasticIP'; Id = $id; Detail = $ip; EstUsdPerMonth = $ipv4PerMonth }
}
foreach ($l in @(aws ec2 describe-snapshots --region $Region --owner-ids self --query "Snapshots[].[SnapshotId,VolumeSize,StartTime]" --output text)) {
  if (-not $l) { continue }
  $id, $size, $start = $l -split "`t"
  if ([datetime]$start -lt (Get-Date).AddDays(-90)) { $rows += [pscustomobject]@{ Type = 'OldSnapshot'; Id = $id; Detail = "$size GiB, $start"; EstUsdPerMonth = [math]::Round([double]$size * $snapPerGb, 2) } }
}
foreach ($l in @(aws ec2 describe-instances --region $Region --filters Name=instance-state-name,Values=stopped --query "Reservations[].Instances[].[InstanceId,InstanceType]" --output text)) {
  if (-not $l) { continue }
  $id, $type = $l -split "`t"
  $rows += [pscustomobject]@{ Type = 'StoppedEC2'; Id = $id; Detail = "$type (volumes still billed)"; EstUsdPerMonth = $null }
}
if ($rows) { $rows | Format-Table -AutoSize } else { "No waste found in $Region" }
'@ | Set-Content C:\aws-lab\Find-Waste.ps1
.\Find-Waste.ps1

In a clean lab account you should see this:

No waste found in ap-south-1

Run it every month in each Region you use. It looks for unattached volumes, Elastic IPs that aren’t attached to anything, snapshots older than 90 days and stopped instances (their volumes are still billed). Cost Explorer and AWS Trusted Advisor have similar checks, but a script you own can run anywhere and feed into a report.

EC2 console volume list filtered to available volumes with no results in ap-south-1
A clean Region in the console: no unattached volumes, idle Elastic IPs, old snapshots or forgotten stopped servers.

✅ Checkpoint: You broke down this month’s cost by service and tag, created the saat-course-tag budget with actual and forecast alerts, looked at the Savings Plans recommendation, and Find-Waste.ps1 reports a clean account.

Break It, Then Fix It

Here’s a script that fails once a month, and the leftovers that cost money every hour.

1Break it: run a cost report on the 1st of the month

Pretend it’s the 1st, when “start of month to today” gives you the same date twice:

$today = (Get-Date).ToString('yyyy-MM-dd')
aws ce get-cost-and-usage --time-period "Start=$today,End=$today" --granularity MONTHLY --metrics UnblendedCost

You’ll get this error:

An error occurred (ValidationException) when calling the GetCostAndUsage operation: Start date (and hour) should be before end date (and hour)

Because the end date is exclusive, an empty range is invalid. So scheduled cost reports that work all month fail on every 1st, which happens to be when finance wants last month’s numbers. Fix: handle the 1st explicitly, the way step 1 does, by reporting the previous month or using tomorrow as the end date for “today so far”.

2Break it: leave an Elastic IP and a volume behind

Create the two most common leftovers and then run the waste finder:

$eip = aws ec2 allocate-address --domain vpc --tag-specifications 'ResourceType=elastic-ip,Tags=[{Key=course,Value=saatvedha-aws},{Key=lesson,Value=36}]' --query AllocationId --output text
$vol = aws ec2 create-volume --availability-zone ap-south-1a --size 1 --volume-type gp3 --tag-specifications 'ResourceType=volume,Tags=[{Key=course,Value=saatvedha-aws},{Key=lesson,Value=36}]' --query VolumeId --output text
aws ec2 wait volume-available --volume-ids $vol
.\Find-Waste.ps1

You should see something like this:

Type      Id                         Detail            EstUsdPerMonth
----      --                         ------            --------------
EBSVolume vol-0a1b2c3d4e5f60082      1 GiB gp3, ap-south-1a          0.09
ElasticIP eipalloc-0a1b2c3d4e5f60081 13.234.56.78                    3.65
Cost problems: Cost Explorer empty date range on the 1st, idle Elastic IP and volume found
Both problems and their fixes. Something like this.

An Elastic IP that isn’t attached to anything costs about USD 3.65 a month, more than this small volume does, and big accounts often have hundreds of each left behind by deleted servers, NAT gateways and tests. Fix: release and delete whatever nobody owns (snapshot the volumes first if anyone might need the data), and put the script on a schedule:

aws ec2 release-address --allocation-id $eip
aws ec2 delete-volume --volume-id $vol
aws budgets delete-budget --account-id $acct --budget-name saat-course-tag
Remove-Item budget.json, budget-notifications.json
.\Find-Waste.ps1

You should see this:

No waste found in ap-south-1

The budgets from Lesson 2 stay. Keep Find-Waste.ps1 and run it after every lab, alongside Find-LabResources.ps1.

✅ Checkpoint: You fixed the 1st-of-month date bug, and found and removed an idle Elastic IP and an unattached volume. The extra budget is deleted and Find-Waste.ps1 is saved.

This happened at work

The NAT gateways nobody remembered

Over six months a media company’s AWS bill crept up 30 percent, and they hadn’t launched any new products. Cost Explorer by service showed EC2-Other as the biggest growth, which on its own tells you almost nothing.

It was only when someone grouped by usage type that it showed up: NAT gateway hours and NAT data processing. Every new test VPC built from a template came with three NAT gateways, one per zone, and since test VPCs were hardly ever deleted there were 41 of them by then.

On top of that, servers were pulling container images and S3 data through NAT rather than VPC endpoints, and paying for every GB.

The team deleted the idle VPCs, added S3 and ECR endpoints, cut test VPCs down to one NAT gateway, tagged everything with an owner and set per-team budgets with forecast alerts. The bill fell below where it had started, and a Compute Savings Plan on the steady base that was left took off another fifth.

Common mistakes and troubleshooting

MistakeWhat happensWhat to do
Buying Savings Plans before cleanupPaying for waste for yearsClean up and rightsize first; cover the steady base
Tags not activated for cost allocationTag reports show nothingActivate tags in Billing; they apply from activation onwards
Budgets on actual spend onlyYou learn after the money is spentAdd forecasted alerts
Cost scripts with start equal to endFail on the 1st of every monthEnd is exclusive; handle the 1st
Idle Elastic IPs and unattached volumesCharges every hour, foreverRun a waste finder monthly in every Region
Traffic through NAT that could use endpointsPer-GB processing chargesGateway endpoints for S3 and DynamoDB, interface endpoints where volume justifies

Interview questions

Click a question to open it. Each one is phrased the way an interviewer would ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. Your manager says this month’s AWS bill is higher than usual and asks you to find out why. Where would you start?

Why they ask this: They want to know you can use the basic cost tools without help, because sooner or later every admin gets asked about the bill.

How you might answer: I’d open Cost Explorer, group by service and compare this month with last month to see which service grew most. Then I’d break that service down by usage type, account, Region and cost allocation tags.

That usually leads me to the actual resources and the team that owns them.

2. What’s the difference between an actual budget alert and a forecasted budget alert?

Why they ask this: They’re checking you know how to get warned early, and not only after the money’s gone, since forecasted alerts give you time to act.

How you might answer: An actual alert fires once spend has already reached the threshold, while a forecasted alert fires when AWS predicts you’ll go over by the end of the period.

I set both, because the forecasted one gives me time to fix things before the month closes.

3. If you had one hour to look for wasted money in an AWS account, what would you check first?

Why they ask this: They want practical experience with the usual waste, the quick wins that every cost review finds.

How you might answer: I’d start with unattached EBS volumes, unassociated Elastic IPs and old snapshots, because they’re easy to find and safe to clean up. After that I’d look at idle NAT gateways and load balancers, over-sized instances and log groups with no retention.

2–5 years experience

4. Finance asks if you should buy Savings Plans. How would you decide, and which type would you pick?

Why they ask this: They want to see you think carefully before committing money for years, because buying commitments too early locks in waste.

How you might answer: I’d only buy Savings Plans for steady, predictable usage, and only after rightsizing and cleanup so I’m not committing to waste. Compute Savings Plans are flexible across instance families, Regions, Fargate and Lambda.

EC2 Instance Savings Plans give a bigger discount but tie you to one instance family and Region, so I’d only use them where that usage isn’t going to change.

5. You built a cost report by the Team tag, but last month shows nothing. Why might that be?

Why they ask this: They’re checking you understand how cost allocation tags work, since this catches out a lot of people the first time they report by tag.

How you might answer: Either the tag wasn’t activated for cost allocation back then, or the resources weren’t tagged. Activating a tag only applies to costs from that moment on, so it won’t fill in last month.

That’s why I activate the important tags early, as soon as a new account is set up.

6. The “EC2-Other” line on your bill doubled this month. How would you investigate it?

Why they ask this: They want to see you know what hides inside this confusing line, and it comes up all the time in real cost reviews.

How you might answer: EC2-Other isn’t instances at all. It covers EBS volumes and snapshots, NAT gateway hours and data, data transfer and Elastic IPs.

So I’d group by usage type in Cost Explorer to see which part grew, and then track down the resources and owners behind it.

Senior level

7. A company spending USD 200,000 a month on AWS has no cost control at all. How would you set up FinOps practices for them?

Why they ask this: They want cost governance at scale, meaning ownership, visibility, alerts and regular review, and whether you can make cost everyone’s job and not only finance’s.

How you might answer: I’d make owner and cost-centre tags mandatory, enforced through tag policies and SCPs, give each team its own account, and put budgets with forecasts and anomaly detection on every account.

Each month we’d go through Cost Explorer and the Cost and Usage Report in Athena, rightsize with Compute Optimizer and shut down non-prod on a schedule, and every quarter I’d revisit the Savings Plans strategy.

8. Developers have sandbox accounts, and one of them accidentally left something huge running. How would you stop a runaway cost like that automatically?

Why they ask this: They want to see you build guardrails as well as reports, so damage is limited without someone watching all the time.

How you might answer: I’d set a budget with a budget action that kicks in once actual spend passes a threshold, and the action can apply a restrictive SCP or IAM policy or stop the instances.

Anomaly alerts would also go to the account owner, so they know what happened and why.

Quick quiz

Q1. Why should Savings Plans come after cleanup?

  1. They are cheaper later
  2. Otherwise you commit to paying for waste
  3. They need tags
  4. They only cover S3
Show answer

B — Rightsize and clean up, then commit to the steady base.

Q2. What does course$ mean in a tag cost report?

  1. A broken tag
  2. Cost with no value for the course tag
  3. Tax only
  4. Credits only
Show answer

B — It is untagged spend for that tag key.

Q3. Why did the cost query fail with Start equal to End?

  1. Wrong Region
  2. End date is exclusive, so the range was empty
  3. No permission
  4. Cost Explorer was off
Show answer

B — Handle the 1st of the month explicitly.

Q4. Which budget alert warns you before money is spent?

  1. Actual
  2. Forecasted
  3. Both equally
  4. Neither
Show answer

B — Forecasted alerts give time to act.

Q5. What does an unassociated Elastic IP cost?

  1. Nothing
  2. About USD 3.65 a month
  3. USD 100 a month
  4. Only data transfer
Show answer

B — All public IPv4 addresses are charged hourly.

Quick recap

  • See cost by service, usage type and activated tags in Cost Explorer.
  • Budgets with forecasted alerts warn you in time.
  • Find and remove idle Elastic IPs, unattached volumes and old snapshots regularly.
  • Rightsize and clean up before buying Savings Plans.
  • Cost Explorer end dates are exclusive; handle the 1st of the month.

Next lesson

Lesson 37: Site-to-Site VPN and Direct Connect → Next you’ll connect a simulated office network to saat-vpc with a Site-to-Site VPN and see when Direct Connect is worth paying for.

Further reading: AWS cost optimization

Want to go deeper into AWS cost optimization? Read Analyzing your costs with AWS Cost Explorer and Managing your costs with AWS Budgets. You can also see the full plan for this course on the AWS Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.