Costs, the free tier & the AWS CLI
In the cloud, every resource you forget about keeps costing money, and a leaked key can cost a lot of it. This chapter explains how AWS charges, which discounts exist, what typically causes a surprise bill and how to catch one early. Then it sets up the AWS CLI properly, including profiles and --query, and ends with a checklist for the first hour on a new account.
How AWS charges
Almost everything is metered: compute by the second or hour while it runs, storage by GB-month, requests per thousand or million, and data transfer by GB. Data coming into AWS from the internet is generally free; data going out to the internet is charged; traffic between AZs and between regions is charged too. Prices differ by region. Most Linux EC2 instances are billed per second (with a one-minute minimum). A stopped instance costs nothing for compute, but its disks and any public IPv4 addresses still cost money. Estimate with the AWS Pricing Calculator and check each service's pricing page for current numbers.
Pricing models
| Model | How it works | Best for |
|---|---|---|
| On-Demand | Pay the list price for what runs, no commitment | Learning, new or unpredictable workloads, short experiments |
| Savings Plans | Commit to spending a fixed amount per hour for 1 or 3 years in return for a lower rate. Compute Savings Plans apply across EC2 (any family, size or region), Fargate and Lambda; EC2 Instance Savings Plans are tied to one instance family in one region and discount more; Database Savings Plans (announced late 2025) cover managed databases | Steady baseline usage you're confident will continue |
| Reserved Instances | Commit to specific instance attributes (type, region, platform) for 1 or 3 years. The older model; for EC2, AWS now recommends Savings Plans | Services and cases that Savings Plans don't cover |
| Spot Instances | Use AWS's spare EC2 capacity at a large discount; AWS can take it back with a two-minute warning | Interruption-tolerant work: CI runners, batch jobs, stateless workers in an Auto Scaling group |
Commitments can be paid all upfront, partially upfront or with no upfront payment; more upfront means a bigger discount. Never commit before you know your real usage: a Savings Plan is billed whether you use it or not.
The free tier (read the current page)
AWS changed its free tier on 15 July 2025. Accounts created since then get sign-up credits (with more earned by trying certain services) and choose between a free plan, which runs for a limited period (up to six months) or until the credits are used and doesn't charge your card, and a paid plan, where credits are used first and normal billing follows. Accounts created before that date keep the older model: 12 months of limited free usage for certain services, such as a small instance for a set number of hours per month. On both, some services have an always-free monthly allowance. The details (amounts, eligible instance types, which services are excluded) change, so check the AWS Free Tier page and the Free Tier and Credits pages in the Billing console for your own account. "Free tier eligible" in the console means eligible for your account's plan, within its limits, not free without limit.
What causes surprise bills
- Forgotten resources: an instance, a database or a load balancer from last week's tutorial, often in a different region from the one the console is showing.
- NAT gateways: an hourly charge per gateway plus a charge per GB processed, even when nothing interesting is happening. Tutorials create them readily. Add an S3 gateway endpoint so S3 traffic skips the NAT.
- Data transfer out: large downloads, video, or a popular file served straight from S3 or EC2. A CDN helps, but transfer is never free at scale.
- Leftover storage: unattached EBS volumes (status
available), old snapshots, and AMIs (deregistering an AMI does not delete its snapshots). - Public IPv4 addresses: every one is billed hourly, including idle Elastic IPs.
- Things that restart: a stopped RDS instance starts again automatically after seven days.
- Logs kept forever: CloudWatch Logs groups default to "Never expire". Set a retention period.
- Services with a base fee: EKS clusters, interface VPC endpoints, idle load balancers.
- Leaked access keys: attackers launch expensive instances in every region within minutes. Use roles, never commit keys, and enable MFA.
Budgets and alerts
Set these up before you build anything:
- AWS Budgets (Billing and Cost Management → Budgets): create a monthly cost budget with email alerts on actual spend (say at 80%) and forecasted spend (at 100%). The zero spend budget template alerts you the moment anything costs more than a cent. Budgets check a few times a day, so they warn you; they don't stop resources.
- Cost Explorer: charts of spend by service, region, day and tag. The first place to look when a bill surprises you.
- Cost Anomaly Detection: learns your normal spend and alerts on unusual jumps. Check that a monitor exists and that its alerts go to an address you read.
- Billing preferences: turn on free tier usage alerts, and "Receive CloudWatch billing alerts" if you want CloudWatch alarms on the
EstimatedChargesmetric (billing metrics live inus-east-1).
A budget can also be created from the CLI:
# budget.json
{
"BudgetName": "monthly-limit",
"BudgetLimit": { "Amount": "10", "Unit": "USD" },
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}
# notifications.json
[
{
"Notification": { "NotificationType": "ACTUAL", "ComparisonOperator": "GREATER_THAN",
"Threshold": 80, "ThresholdType": "PERCENTAGE" },
"Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "[email protected]" } ]
}
]
$ aws budgets create-budget --account-id 123456789012 \
--budget file://budget.json --notifications-with-subscribers file://notifications.json
Tagging
Tags are key-value labels on resources, such as Project=practice, Env=dev, Owner=demee. Tag everything from day one (Terraform's default_tags makes this automatic). Tags let you find and delete everything belonging to one experiment, and, once you activate them as cost allocation tags in the Billing console, split the bill by project in Cost Explorer. Activation isn't retroactive: only costs from after activation are grouped by tag.
$ aws ec2 create-tags --resources i-0abc1234def567890 vol-0123456789abcdef0 \
--tags Key=Project,Value=practice Key=Env,Value=dev
$ aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=practice \
--query 'ResourceTagMappingList[].ResourceARN' --output text
Cleaning up
When an experiment is over, delete it the same way you built it: terraform destroy for Terraform projects, deleting the stack for CloudFormation, otherwise by hand in reverse order (instances and load balancers, then NAT gateways and Elastic IPs, then volumes, snapshots and buckets, and finally the VPC). Then sweep every region for leftovers:
$ for r in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
echo "== $r"
aws ec2 describe-instances --region "$r" \
--query 'Reservations[].Instances[].[InstanceId,State.Name,InstanceType]' --output text
done
# unattached volumes and unassociated Elastic IPs in the current region
$ aws ec2 describe-volumes --filters Name=status,Values=available \
--query 'Volumes[].[VolumeId,Size,CreateTime]' --output table
$ aws ec2 describe-addresses --query 'Addresses[?AssociationId==`null`].[PublicIp,AllocationId]' --output table
The Billing console's Bills page, broken down by service and region, is the final check: anything still charging shows up there.
Installing the AWS CLI v2
# Linux (x86_64; use awscli-exe-linux-aarch64.zip on ARM)
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install # add --update to upgrade an existing install
$ aws --version
aws-cli/2.x.x Python/3.x.x Linux/...
# macOS
$ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
$ sudo installer -pkg AWSCLIV2.pkg -target /
# Windows (run in PowerShell or cmd)
$ msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Don't use pip install awscli: that installs the old version 1, which lacks v2 features such as aws login, SSO support and the --cli-binary-format option.
Credentials and profiles
The CLI needs credentials. From best to last resort:
aws login(CLI 2.32 or newer): signs you in through the browser with your normal console sign-in and gives the CLI short-lived credentials that refresh automatically. No keys stored on disk.aws configure ssothenaws sso login: for IAM Identity Center users.aws configurewith an IAM user's access key: long-lived keys in a plain-text file. If you use it, give that user only what it needs and rotate the key.
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: ****************************************
Default region name [None]: eu-central-1
Default output format [None]: json
# ~/.aws/config: settings per profile
[default]
region = eu-central-1
output = json
[profile practice]
region = eu-west-1
output = table
# ~/.aws/credentials: keys per profile (no "profile " prefix here)
[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
$ aws configure --profile practice # create or edit a named profile
$ aws s3 ls --profile practice # use it for one command
$ export AWS_PROFILE=practice # or for the whole shell session
Before doing anything, check who and where you are. Many "it doesn't work" moments are simply the wrong account or region:
$ aws sts get-caller-identity
{
"UserId": "AIDAEXAMPLEUSERID1234",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/demee"
}
$ aws configure get region
Settings are resolved in this order: command-line options (--region, --profile, --output) beat environment variables (AWS_PROFILE, AWS_REGION, AWS_ACCESS_KEY_ID…), which beat the config and credentials files. A forgotten AWS_ACCESS_KEY_ID in your environment silently overrides your profile.
Output formats and --query
--output can be json (default), yaml, text (tab-separated, best for shell scripts) or table (for humans). --region eu-west-1 runs one command against another region. --query filters and reshapes the JSON response using JMESPath, on your machine after the response arrives; --filters, where a command supports it, filters on AWS's side before anything is sent.
# Running instances as a table: ID, type, AZ and the value of the Name tag
$ aws ec2 describe-instances --filters Name=instance-state-name,Values=running \
--query "Reservations[].Instances[].{ID: InstanceId, Type: InstanceType, AZ: Placement.AvailabilityZone, Name: Tags[?Key=='Name'] | [0].Value}" \
--output table
# Just the bucket names, one per line
$ aws s3api list-buckets --query 'Buckets[].Name' --output text
Reading the first query: Reservations[].Instances[] flattens the nested lists into one list of instances; {ID: InstanceId, …} builds a new object for each with the fields you choose; Tags[?Key=='Name'] keeps only tags whose key is Name, and | [0].Value takes the first one's value. Strings inside JMESPath go in single quotes, so wrap the whole query in double quotes in bash. Other handy settings: --no-cli-pager (or export AWS_PAGER="") stops output opening in less, and aws <command> help shows every option.
Your first hour on a new AWS account
- Sign in as root and turn on MFA (a passkey or an authenticator app). Make sure root has no access keys.
- Check the account email and set alternate contacts for billing and security, so AWS's warnings reach you.
- Create an everyday admin identity: an IAM Identity Center user, or an IAM user with MFA in an admins group. Sign out of root and use that from now on.
- Create a zero spend budget and a monthly budget with actual and forecasted alerts; turn on free tier usage alerts; check Cost Anomaly Detection is sending alerts to you.
- Pick a home region close to you and use it consistently.
- Install the CLI v2, run
aws login(oraws configure sso), thenaws sts get-caller-identity. - Confirm S3 Block Public Access is on at account level and turn on EBS encryption by default in your region.
- Look at CloudTrail event history (the last 90 days of management events are visible by default); create a trail to S3 if you want a longer record.
- Decide on tags (at least
Project) and, from the second experiment on, build with Terraform so thatterraform destroycleans up everything.
Common CLI errors
Unable to locate credentials: nothing configured for this profile. Runaws login,aws sso loginoraws configure, or checkAWS_PROFILE.ExpiredTokenor "The SSO session has expired": temporary credentials ran out; log in again.InvalidClientTokenId/SignatureDoesNotMatch: a mistyped, deleted or deactivated access key, or a stale key in environment variables overriding the file.Could not connect to the endpoint URL: usually a misspelled region (eu-central1instead ofeu-central-1).- An empty result when you know the resource exists: you're in the wrong region or account. Check
aws sts get-caller-identityand--region. - Output opens in a pager and a script hangs: add
--no-cli-pageror setAWS_PAGER="".