Sub topic 13
Staying inside the Free Tier: budgets, alerts, and cleanup
This chapter assumes you have an AWS account, can run the AWS CLI with working credentials, and have read the earlier chapters on Regions and the Free Tier models. Here you set up spending alerts and a routine that finds resources you forgot about.
Why charges surprise people
The Free Tier limits what you can use for free. It does not stop AWS from billing you once you go past those limits. Most surprises come from three causes:
- A resource keeps running in a Region you no longer look at.
- A resource keeps costing money after the thing it served is gone, such as an unattached EBS volume.
- A resource is not covered by the Free Tier at all, such as a NAT gateway or a public IPv4 address.
Because resources are regional, the console only shows the Region you have selected. A forgotten instance in ap-southeast-2 is invisible while you work in us-east-1.
Layer 1: Free Tier usage alerts
Turn on Free Tier usage alerts in the Billing console under Billing preferences. AWS emails you when your usage of a Free Tier service nears its limit. If your account is on the newer credit-based plan, also watch your remaining credits and their expiry date. Older accounts follow the legacy model with 12-month offers, always-free offers, and short trials. Check which model applies to your account before you rely on any alert.
Layer 2: a budget with notifications
A budget compares your actual or forecasted spend against a limit you set. Billing and budget APIs are served from us-east-1, whatever Region your workloads use. This example creates a monthly cost budget of 5 USD that emails you at 80 percent of actual spend. Replace the account ID and email address with your own.
{
"BudgetName": "monthly-guardrail",
"BudgetLimit": { "Amount": "5", "Unit": "USD" },
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}Save that as budget.json. Save the next block as notifications.json.
[
{
"Notification": {
"NotificationType": "ACTUAL",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [
{ "SubscriptionType": "EMAIL", "Address": "[email protected]" }
]
}
]aws budgets create-budget \
--region us-east-1 \
--account-id 123456789012 \
--budget file://budget.json \
--notifications-with-subscribers file://notifications.jsonAdd a second notification with "NotificationType": "FORECASTED". It warns you before the money is spent.
Layer 3: a cleanup sweep across Regions
This loop uses the Region listing from earlier in the tutorial. For each enabled Region it prints instances that are running or stopped, unattached EBS volumes, and Elastic IPs that are not associated with anything.
for r in $(aws ec2 describe-regions --query "Regions[].RegionName" --output text); do
echo "== $r"
aws ec2 describe-instances --region "$r" \
--filters Name=instance-state-name,Values=running,stopped \
--query "Reservations[].Instances[].[InstanceId,InstanceType,State.Name]" \
--output text
aws ec2 describe-volumes --region "$r" \
--filters Name=status,Values=available \
--query "Volumes[].[VolumeId,Size]" --output text
aws ec2 describe-addresses --region "$r" \
--query "Addresses[?AssociationId==null].PublicIp" --output text
doneAnything listed deserves a decision: delete it, or note why you keep it. Delete with commands such as aws ec2 terminate-instances, aws ec2 delete-volume, and aws ec2 release-address. Check the ID and Region first, because deletion cannot be undone.
The sweep covers EC2 only. Also check these, which commonly cost money:
- NAT gateways, which bill hourly while they exist.
- Load balancers.
- RDS databases, including stopped ones, because AWS restarts them after seven days.
- Snapshots and S3 buckets.
- Public IPv4 addresses, which AWS bills hourly whether or not they are in use, with an allowance only under some Free Tier terms.
Opt-in Regions you never enabled are not scanned, and that is fine. They cannot hold resources.
Common mistakes
- Setting an alert threshold in dollars higher than the credit you have left.
- Assuming a stopped instance is free. Its EBS volume still bills.
- Using the root user for experiments, which makes it harder to find who created what. Tag resources, for example
purpose=tutorial, so cleanup is searchable. - Deleting only in your usual Region.
Exercise
You terminated your only EC2 instance, but your bill still shows EBS charges. Name two places to look and the CLI filter that finds the likely cause.
Show answer
Look for unattached EBS volumes and for snapshots, and check every Region you have used, not only the current one. Unattached volumes appear with aws ec2 describe-volumes --filters Name=status,Values=available run per Region. A volume can survive instance termination if its DeleteOnTermination flag was false.