Chapter 4 · Part 1: Cloud and AWS Foundations
Your Safe AWS Playground
Goal: create your AWS account the way a professional does, lock it down before you build anything, put a spending alarm in place, learn the console, CloudShell and the AWS CLI, and build the habits (tags, names, cleanup) that keep labs cheap and tidy for the rest of the course.
Reading time: about 55 minutes. Lab time: 45 minutes. Lab cost: about $0.
How to read this chapter: read it, then do the lab in section 4.9 straight away. This is the one chapter where doing matters more than reading. Go Deeper boxes are optional.
Version note: AWS changed its free tier in July 2025 and keeps improving sign-in and billing screens. This chapter was checked against AWS documentation in December 2026. Screens may move around, but the ideas and the order of steps stay the same.
What You Will Be Able to Do After This Chapter#
- Create an AWS account, secure the root user with MFA, and say why you never use root for daily work.
- Explain the Free plan, credits and "always free" offers, and what is not free.
- Create a budget with email alerts, and explain why a budget alert is a smoke alarm, not a sprinkler.
- Move around the console, open CloudShell, install the AWS CLI v2, and sign in from it without long-lived keys.
- Name and tag resources so you can find them, and so you can delete them later.
- Do the same task six ways (console, CLI, CloudShell, SDK, infrastructure as code, raw API) and explain that all six are the same API underneath.
- Name the 25 services that appear in most real architectures and say what each one is for.
- Run a cleanup routine that finds forgotten resources in every Region.
The Big Picture: Moving Into a New Apartment#
Opening an AWS account is like moving into a new apartment where the landlord lets you build anything, and charges by the hour. A sensible tenant does five things on day one.
| Day-one task | Apartment analogy | AWS step |
|---|---|---|
| 1. Lock the master key away | Put the landlord's master key in a safe, and use a normal door key | Secure the root user with MFA, then stop using it |
| 2. Make your daily key | Cut a key that opens your door, not every door in the building | Create an admin identity for daily work |
| 3. Install a smoke alarm | You want a loud warning before the fire is big | Create a budget with alerts |
| 4. Learn where the switches are | Find the fuse box, the water valve and the light switches | Learn the console, CloudShell and CLI |
| 5. Label everything and tidy up | Name the boxes, and take the rubbish out every evening | Tags, names and a cleanup routine |
YOU --(email + password + MFA)--> ROOT USER (all powers, locked away, used almost never)
|
| creates once
v
ADMIN IDENTITY (daily work, MFA on) --> builds labs --> tags everything --> cleans up daily
|
+--> BUDGET watches the bill and emails youThe whole chapter in 60 seconds: sign up, then immediately turn on MFA for the root user, add alternate contacts, and create a separate admin identity for daily work. Never create access keys for root. Pick the Free plan while learning: you get up to $200 in credits for 6 months and no surprise charges, but free is not unlimited, and services such as NAT gateways, load balancers and big databases burn credits fast. Create a budget with email alerts first (it warns, it does not stop spending). Use the console to explore, CloudShell for zero-setup commands, and the CLI with aws login or SSO on your laptop. Everything you click is an API call. Tag every lab resource (Lab=ch04) and delete it the same day.
Jargon Buster#
| Term | Plain meaning |
|---|---|
| AWS account | A container for all your resources and your bill, with a 12-digit account ID. It is the basic security and billing boundary. |
| Root user | The identity created with the account, using the sign-up email. It has unlimited power and cannot be restricted. Protect it, then leave it alone. |
| IAM user / identity | A person or program you create inside the account, with only the permissions you give. (Chapter 6.) |
| MFA | Multi-factor authentication: a password plus something you have (a phone app, a security key or a passkey). |
| Free plan / credits | A starter offer for new accounts: credits that pay for usage, for a limited time. |
| Budget | A spending limit you define, which sends alerts when real or forecast spend crosses a threshold. |
| Console | The AWS website where you click to manage resources. |
| CLI | Command Line Interface: a program (aws) that lets you control AWS by typing commands. |
| CloudShell | A free terminal inside the console, already signed in, with the CLI installed. |
| SDK | Software Development Kit: a code library (for Python, JavaScript, Java and more) to call AWS from programs. |
| Access key | A long-lived ID and secret pair for programs. Powerful, easy to leak, best avoided. Prefer temporary credentials. |
| Profile | A named set of CLI settings (Region, sign-in method), so you can switch between accounts easily. |
| Tag | A label (key and value) you attach to a resource, for finding it, grouping it and tracking its cost. |
| ARN | Amazon Resource Name: the unique "full address" of any resource. |
| Quota | A limit on how many of something you may create (also called a service limit). |
4.1 Creating an Account the Right Way#
The sign-up steps#
- Choose an email you will keep for years. This becomes the root user's login and the place password-reset mail goes. Use a mailbox you control with its own strong password and MFA, not a throwaway address. For a company, use a shared mailbox such as
aws-root@yourcompany.comso the account does not depend on one person. - Pick an account name (for example
stackcafe-learning) and verify the email with the code AWS sends. - Set a long, unique root password (a password manager helps).
- Add contact details (personal or business).
- Add a payment method. AWS needs a valid card even for the Free plan.
- Verify your identity by phone (a text message or a call).
- Choose the plan: start with the Free plan (see 4.2), and the Basic support plan (free).
Immediately after sign-up: lock the root user#
The root user can do everything: close the account, change the payment method, remove any protection you add. It cannot be limited by IAM policies. If someone steals the password, they own your account and your bill. So you do four things, in this order, before anything else:
| # | Action | Where | Why |
|---|---|---|---|
| 1 | Turn on MFA for root, using a passkey or security key, or an authenticator app. Register a second MFA device as a backup | Console: account menu, then Security credentials | Stops a stolen password from being enough. AWS now expects MFA on root users |
| 2 | Add alternate contacts for billing, operations and security | Account menu, then Account | AWS can reach the right person with cost, outage or abuse notices |
| 3 | Never create access keys for root, and delete any that exist | Security credentials | Root keys are the most dangerous secret in AWS |
| 4 | Create an admin identity for daily work, then stop using root | IAM (this chapter's lab), IAM Identity Center (Chapter 7) | Everyday work should never run with unlimited power |
Also set now (two minutes each)#
- Account alias: a friendly sign-in name such as
stackcafe-learninginstead of the 12-digit ID. - IAM access to billing: by default only root can open the Billing pages. Turn on IAM user and role access to Billing information so your admin identity can see costs, so you do not need root for that.
- Free tier usage alerts: in Billing preferences, switch on alerts so AWS emails you when you approach free limits.
MFA ranking, strongest first: a hardware security key or passkey (it cannot be phished), then an authenticator app (a code that changes every 30 seconds), then SMS (avoid, where AWS offers a choice). Keep your backup device somewhere different from your first one.
"It is just my practice account, so root is fine." Attackers scan for leaked keys all day, and a compromised practice account is used to mine cryptocurrency on your card within minutes. The habits you build now are the habits you take to a real job. Do it properly from day one.
Go DeeperWhat only the root user can do (the short, rare list)
A small set of tasks still needs the root user. You will do them rarely, then lock root away again.
- Change the account name, root email address or root password.
- Close the AWS account.
- Change or cancel the AWS Support plan, and restore IAM permissions if every admin is locked out.
- A few special tasks: for example, configure an S3 bucket policy that blocks all access, or sign up for GovCloud. (AWS publishes the full list in the IAM documentation under "Tasks that require root user credentials".)
In a company you also protect the root email address and phone number, because whoever controls them can take over the account through a password reset. That is why they should be shared, monitored mailboxes and numbers, not one person's.
Go DeeperPreview: why real companies use many accounts
One account is fine for learning. Companies use many: one for production, one for testing, one for security logs, one per team. Accounts are the strongest wall in AWS: a mistake or breach in one does not spill into another. Chapter 8 covers AWS Organizations and Control Tower, and Chapter 7 shows how people sign in to many accounts with a single login. For now, remember that "account" is a boundary, not just a login.
4.2 The Free Tier and Credits: What Is Free and What Is Not#
AWS gives you three kinds of free usage. Knowing which is which prevents most surprise bills.
| Kind | What it is | Example | Lasts |
|---|---|---|---|
| Free plan credits (new accounts) | Credits that pay for usage. You get $100 at sign-up and can earn up to $100 more by trying key services, so up to $200 in total | Launch an EC2 instance, and the hours are paid from credits | The Free plan ends after 6 months or when the credits run out, whichever comes first. Credits must be used within 12 months of account creation |
| Always free offers | Small monthly allowances that never expire | For example Lambda: 1 million requests a month. SQS and SNS have a free million requests too. (Check the Free Tier page for the current list.) | Forever, per month |
| Short trials | Time-limited trials of specific services | A few weeks of a particular service | Days or weeks |
Accounts created before July 2025 may still be on the older "12 months free" model. This course assumes a new account.
Free plan or Paid plan?#
| Free plan | Paid plan | |
|---|---|---|
| Starting credits | Up to $200 | The same credit offer |
| Can I be charged? | No. When credits or 6 months run out, the plan ends and you must upgrade to continue | Yes, after credits are used. Credits still apply first |
| Services available | Most services. Some services and features are limited | All services |
| Best for | Learning, with a built-in spending safety net | Production, or labs that need restricted services |
Recommendation: start on the Free plan. It cannot surprise you. Upgrade only when you deliberately need more. Even then, your remaining credits are applied to your bill first.
What eats your credits quickly#
Credits are real money to AWS, so these items drain them. Each lab tells you which of these it creates.
| Service | Why it costs even when idle | Rough size (check pricing) |
|---|---|---|
| NAT gateway | Hourly charge plus a charge per GB processed | About $30 to $45 a month if left on |
| Load balancer (ALB, NLB) | Hourly charge while it exists | About $16 and up a month |
| EKS control plane | Hourly charge per cluster | About $72 a month |
| Public IPv4 address | Every public IPv4 address is charged by the hour, even attached to a stopped server | About $3.60 a month each |
| RDS and Aurora databases | Instance hours, storage and backups | From a few dollars up to hundreds a month |
| EBS volumes and snapshots | Charged per GB even when no server is attached | Cents per GB a month |
| Data transfer out to the internet | Per GB after a small free allowance | Around $0.09 per GB |
"Free tier means unlimited and automatic." It means limited allowances and credits. Launching a big instance, a NAT gateway, or leaving a database running can use up your whole credit balance in days. Also, "stopped" is not "deleted": a stopped server still pays for its disk and its public IP.
4.3 Budgets and Alerts: Install the Smoke Alarm First#
AWS Budgets lets you define how much you plan to spend, and emails you when actual or forecast spend crosses a percentage of it. It is the first thing to create in any new account.
| Alert | Type | Meaning |
|---|---|---|
| 50 percent of the budget | Actual | "You are halfway. Is that expected?" |
| 80 percent of the budget | Actual | "Look now." |
| 100 percent of the budget | Forecast | "At this pace you will pass your limit. Act before it happens." |
Create it in the console#
- Open Billing and Cost Management, then Budgets, then Create budget.
- Choose Use a template, then Monthly cost budget.
- Enter an amount you are comfortable with (for example $10 for learning) and your email address.
- Create it. The template adds a sensible alert for you.
- Open it afterwards and add the 50 percent and 100 percent forecast alerts from the table above.
Or create it with the CLI (a first taste of infrastructure as code)#
# budget.json
{
"BudgetName": "monthly-learning-budget",
"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": "you@example.com" }]
}
]
# create it (replace the account ID)
aws budgets create-budget \
--account-id 123456789012 \
--budget file://budget.json \
--notifications-with-subscribers file://notifications.jsonThree more cost tools to know (more in Chapter 5)#
| Tool | What it does |
|---|---|
| Cost Explorer | Graphs of your spend by service, Region, tag and day. Turn it on the first day, because history only starts when you enable it |
| Cost Anomaly Detection | Learns your normal spending and emails you when something suddenly jumps |
| Billing and Cost Management home | Month-to-date spend, forecast and free-tier usage in one view |
A budget alert does not stop anything. It is an email, not a circuit breaker. Billing data also arrives with a delay of several hours, sometimes up to a day, so a runaway resource can burn money before the email lands. The only real protection is the combination: Free plan, small labs, daily cleanup, and alerts you actually read. (Budget actions can attach a restrictive policy automatically, which Chapter 5 shows.)
Your first two or three budgets are free or nearly free. Check the Budgets pricing page for the current allowance. Never skip the alarm to save pennies.
4.4 Console Tour, CloudShell, AWS CLI v2 and Named Profiles#
The console in one picture#
+------------------------------------------------------------------------------------------+
| [aws logo] [ Services ] [ Search: "type a service or feature" ] [>_ CloudShell] [bell] |
| [ Mumbai v ] <- REGION [ account name v ] |
+------------------------------------------------------------------------------------------+
| Console home |
| Recently visited | Cost and usage | Health | Applications / resources |
+------------------------------------------------------------------------------------------+
Search bar = fastest way to any service (type "ec2", "s3", "iam")
>_ icon = opens CloudShell, a free terminal in your browser
Region menu = which Region you are looking at. CHECK IT FIRST, ALWAYS (Chapter 3)
Account menu = account ID, security credentials, billing, sign out| Habit | Why |
|---|---|
| Glance at the Region menu before you click anything | Most "my resource disappeared" stories are a wrong Region |
| Use the search bar instead of menus | It is quicker and survives menu redesigns |
| Star or pin your favorite services | Saves clicks |
| Read the pricing note on create screens | Many screens show an estimate |
CloudShell: a ready terminal with no setup#
AWS CloudShell is a browser-based terminal that opens from the >_ icon. It is already signed in as you, with the AWS CLI, Python, Node.js, Git and jq installed. It is free, and it keeps a small home directory (about 1 GB) per Region between sessions. It is perfect for learning because nothing needs installing, and there are no credentials on your laptop to lose.
| Good for | Not for |
|---|---|
| Running CLI commands from the labs, quick scripts, checking things | Long-running jobs (sessions time out when idle) |
| Working without installing anything | Heavy development. Use your own laptop and editor |
Install the AWS CLI v2 on your own computer#
# Linux (x86_64)
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o awscliv2.zip
unzip awscliv2.zip && sudo ./aws/install
# macOS: download and run the official .pkg installer from the AWS CLI documentation
# Windows: download and run the official .msi installer from the AWS CLI documentation
aws --version # confirm it works. It should say aws-cli/2.xSigning in from the CLI without long-lived keys#
The old way was to create an access key and paste it into aws configure. It works, but a key that never expires is a leak waiting to happen. Today there are better options. Use them in this order.
| Rank | Method | How | Credentials |
|---|---|---|---|
| 1 | IAM Identity Center (SSO) | aws configure sso, then aws sso login (Chapter 7) | Temporary, centrally managed. Best for teams |
| 2 | aws login with your console sign-in | Run aws login, sign in in the browser. (Add --remote if you work on a machine without a browser) | Temporary, refreshed automatically. Great for a single learner account |
| 3 | CloudShell | Nothing to do. Already signed in | Temporary |
| 4 (avoid) | IAM user access keys | aws configure | Long-lived. Only for tools that cannot do anything else, and rotate them |
Both aws login and SSO need a recent version of the CLI v2. If the command is not found, update the CLI.
Named profiles: one laptop, many accounts#
The CLI stores settings in ~/.aws/config. A profile is a named block, so you can switch between accounts, roles and Regions without retyping anything.
# ~/.aws/config
[default]
region = ap-south-1
output = json
[profile stackcafe-learning]
region = ap-south-1
output = tableaws sts get-caller-identity # WHO AM I? Shows account ID and identity
aws sts get-caller-identity --profile stackcafe-learning # the same, using a named profile
export AWS_PROFILE=stackcafe-learning # use that profile for this terminal session
aws ec2 describe-regions --output table # --output: json, table, text
aws ec2 describe-regions --query "Regions[].RegionName" # --query filters the answer (JMESPath)The command to run when confused: aws sts get-caller-identity. It prints the account ID and identity you are using right now. Half of "access denied" and "wrong account" mysteries end the moment you run it.
Go DeeperWhere does the CLI look for settings? (the order matters)
When you run a command, the CLI picks settings in this order, from strongest to weakest:
- Command-line options, such as
--regionand--profile. - Environment variables, such as
AWS_REGIONandAWS_PROFILE. - The profile in
~/.aws/config(and the shared credentials file). - Container or instance credentials, for code running on AWS (a Lambda role, an EC2 instance role).
This is why a script that works on your laptop can behave differently in CI or on a server: a stray environment variable beats your profile. When in doubt, run aws configure list to see which source won.
4.5 Regions, Tagging and Naming Conventions That Save You Later#
Pick one Region and stick to it#
Remember from Chapter 3: resources live in a Region. Set your default Region once (ap-south-1 for this course) in the console, in your CLI profile and in your tools. Mixing Regions is the number one cause of "I cannot find it".
A naming convention#
Good names make a list readable and let you search. A simple pattern:
<app>-<environment>-<what>-<optional number>
stackcafe-dev-web-01 a web server in the dev environment
stackcafe-prod-orders-db the production orders database
stackcafe-lab-ch04-bucket a throwaway lab bucket for Chapter 4Rules: lowercase letters, digits and hyphens. No spaces or personal names. Some resources, such as S3 buckets, need globally unique names, so add your account ID or a random suffix.
Tags: the labels that run your cloud#
A tag is a key and value attached to a resource. Tags do four jobs: find things, group them, allocate cost (see what each project spends) and control access (in advanced policies). Use a small, fixed set of keys.
| Tag key | Example value | Purpose |
|---|---|---|
Project | stackcafe | Which product it belongs to |
Environment | dev, test, prod | What stage it serves |
Owner | maya@stackcafe.example | Who to ask, and who gets the bill |
CostCenter | 1234 | Finance grouping |
Lab | ch04 | Course helper: find and delete everything from one lab in one search |
- Tag keys are case-sensitive:
Projectandprojectare different. Pick one style and keep it. - For tags to appear in cost reports you must activate them as cost allocation tags in the Billing console. Tags only start counting after activation.
- Not every resource supports every tag action, but nearly all do. Tag as you create.
ARN: the full address of any resource#
Every resource has a unique ARN. You will see ARNs in every permission policy.
arn : aws : s3 : : : my-bucket/menu.png an S3 object (no Region or account in the ARN)
arn : aws : ec2 : ap-south-1 : 123456789012 : instance/i-0abc123
| | | | | |
| | | | | +-- the resource type and ID
| | | | +------------------- the 12-digit account ID
| | | +---------------------------------- the Region (blank for global resources)
| | +------------------------------------------- the service
| +------------------------------------------------- the partition (aws, aws-cn, aws-us-gov)
+------------------------------------------------------- always "arn"StackCafe rule: every resource Maya creates gets Project=stackcafe, Environment=... and Owner=.... In Chapter 8 she will make this mandatory with a policy, so an untagged resource simply cannot be created. Start the habit now, while it is free.
4.6 Six Ways to Talk to AWS (and the One Truth Underneath)#
You can control AWS in six ways. They look different, but every one of them ends the same way: an HTTPS API call, signed with your credentials, checked by IAM, then executed by the service.
Console (click) --+
CLI (type) --+
CloudShell --+---> AWS API endpoint ---> IAM checks "is this allowed?" ---> the service does it
SDK (code) --+ (HTTPS + signature) (Chapter 6) (create, change, delete)
IaC (templates) --+
Raw HTTPS call --+One task, six ways: create a storage bucket#
| Way | What you do | Best for |
|---|---|---|
| 1. Console | Open S3, click Create bucket, type a name, pick the Region | Exploring, learning, one-off checks |
| 2. CLI | One command (below) | Quick tasks, scripts, repeatable steps |
| 3. CloudShell | The same command, in the browser terminal | Zero-setup CLI |
| 4. SDK | A few lines of Python or JavaScript inside your application | Apps that need AWS at run time |
| 5. Infrastructure as code | A template that describes the bucket, deployed as a stack | Real environments: repeatable, reviewable, deletable in one go (Chapter 34) |
| 6. Raw API | Send a signed HTTPS request yourself | Almost never. It shows what the others do for you |
# 2 and 3. CLI (works in CloudShell too)
aws s3api create-bucket \
--bucket stackcafe-lab-ch04-123456789012 \
--region ap-south-1 \
--create-bucket-configuration LocationConstraint=ap-south-1# 4. SDK (Python, library name: boto3)
import boto3
s3 = boto3.client("s3", region_name="ap-south-1")
s3.create_bucket(
Bucket="stackcafe-lab-ch04-123456789012",
CreateBucketConfiguration={"LocationConstraint": "ap-south-1"},
)# 5. Infrastructure as code (CloudFormation)
Resources:
LabBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: stackcafe-lab-ch04-123456789012
Tags:
- { Key: Lab, Value: ch04 }The learning path inside this course: click in the console first to see what exists, then repeat the same thing with the CLI to see the parameters, and from Chapter 34 write it as code. The console teaches you the concepts. The code makes it repeatable. A professional ends up mostly in code.
Go DeeperWhat a raw API call looks like (and why signing matters)
Every request to AWS carries a signature (called Signature Version 4) computed from your secret key, the request and the time. AWS recalculates it, and if it matches, it knows who sent it and that the request was not altered. The CLI and SDKs do this for you.
The idea is the key to security: your secret key never travels. Only a signature does, valid for minutes. That is also why temporary credentials are safer. A stolen signature expires in minutes. A stolen long-lived key works until someone notices.
4.7 The Service Map: 25 Services That Cover 90 Percent of Real Designs#
AWS has more than 200 services, which overwhelms beginners. The truth is that most architectures use a small core. Learn these 25 first. Every one has its own chapter later, so this is a preview map, not an exam.
| Group | Service | One-line job | Everyday comparison | Chapter |
|---|---|---|---|---|
| Compute (where code runs) | EC2 | Virtual servers you manage | A rented empty flat | 15, 16 |
| Lambda | Run a function when something happens | A vending machine that cooks one slice | 17 | |
| ECS and Fargate | Run containers, with no servers to manage on Fargate | Shipping containers, with a port crew provided | 18 | |
| EKS | Kubernetes, managed | A big container terminal with its own rules | 19 | |
| Storage (where files live) | S3 | Unlimited object storage | An endless warehouse with labeled boxes | 21 |
| EBS | A disk for one server | A hard drive | 22 | |
| EFS | A shared network folder | A shared office drive | 22 | |
| Databases (where records live) | RDS and Aurora | Managed relational (SQL) databases | A well-run filing office | 24 |
| DynamoDB | Serverless key-value database | A giant lightning-fast index-card box | 25 | |
| ElastiCache | In-memory cache | A sticky note on the desk | 26 | |
| Networking and edge (how things connect) | VPC | Your private network | A gated neighborhood | 10, 11 |
| Route 53 | DNS: names to addresses | A phone book | 13 | |
| CloudFront | Global content delivery and cache | Local shops stocking popular goods | 13 | |
| Elastic Load Balancing | Spreads traffic across servers | A restaurant host seating guests | 14 | |
| API Gateway | A managed front door for APIs | A reception desk | 28 | |
| Security and identity (who and what is protected) | IAM | Who may do what | Building access badges | 6 |
| KMS | Create and control encryption keys | A locksmith and a key safe | 9 | |
| WAF | Block bad web requests | A bouncer | 38 | |
| Integration (how parts talk) | SQS | A queue of messages | A ticket line | 29 |
| SNS | Broadcast a message to many | A loudspeaker | 29 | |
| EventBridge | Route events between services | A smart switchboard | 29 | |
| Management and operations (running it well) | CloudWatch | Metrics, logs and alarms | A dashboard and smoke alarm | 36 |
| CloudTrail | A record of every API call | A security camera log | 36 | |
| CloudFormation | Build infrastructure from templates | Architectural blueprints | 34 | |
| Organizations | Manage many accounts together | A company holding many offices | 8 |
All 25 in one picture: StackCafe, fully grown#
customers --> Route 53 (name) --> CloudFront (cache) --> WAF (filter)
|
+---------------+----------------+
| |
S3 (static site) API Gateway or ALB (front door)
|
+-----------------+-----------------+
| | |
Lambda ECS/Fargate EC2 (compute)
| | |
+--------------------+--------+--------+---------+-------+
| | |
DynamoDB / RDS ElastiCache S3 (files; EBS/EFS disks)
(records) (speed) (storage)
^
SQS / SNS / EventBridge (messages between parts) all inside a VPC (private network)
Watching and governing everything: IAM (who) | KMS (keys) | CloudWatch + CloudTrail (see) |
CloudFormation (build) | Organizations (accounts)How to use this map: do not memorize it. Return to it when a new chapter starts, and find where that service sits. After a few chapters the map becomes second nature, and new services will slot into it easily, because they all answer one of four questions: where does it run, where does the data live, how do the parts talk, and who is allowed.
4.8 Cleaning Up: How to Never Get a Surprise Bill#
Cloud bills rarely come from big mistakes. They come from forgotten small things running for weeks. A tidy routine fixes this.
The usual suspects#
| Forgotten item | Why it keeps costing | How to find it |
|---|---|---|
| Running EC2 instances | Billed every second they run | EC2 console in each Region, or the CLI loop below |
| Unattached EBS volumes and old snapshots | Billed per GB even with no server | EC2, then Volumes, filter by "available" |
| NAT gateways | Hourly plus data charges | VPC console, then NAT gateways |
| Load balancers | Hourly while they exist | EC2, then Load Balancers |
| Public IPv4 addresses and Elastic IPs | Hourly per address | EC2, then Elastic IPs and Network Interfaces |
| RDS and Aurora databases | Instance and storage charges. A stopped RDS instance starts itself again after about 7 days | RDS console |
| EKS clusters | Hourly control plane | EKS console |
| S3 buckets with data, CloudWatch logs | Storage per GB | S3 console, CloudWatch Log groups |
Five habits#
- Tag every lab resource with
Lab=chNN, so you can find them with one search (Resource Groups and Tag Editor). - Delete in reverse order of creation. Things with dependencies (a server in a subnet in a VPC) must be removed from the inside out.
- Prefer templates. If a lab was created with CloudFormation, deleting the stack removes everything in it.
- Do the end-of-day check: look at Cost Explorer for today, and run the sweep script below.
- Check every Region you used, not just the one the console is showing.
A sweep script: find running servers in every Region#
for r in $(aws ec2 describe-regions --query "Regions[].RegionName" --output text); do
aws ec2 describe-instances --region "$r" \
--query "Reservations[].Instances[?State.Name!='terminated'].[InstanceId,InstanceType,State.Name]" \
--output text | sed "s/^/$r /"
done
# Disks not attached to anything (still billing):
aws ec2 describe-volumes --region ap-south-1 \
--filters Name=status,Values=available \
--query "Volumes[].[VolumeId,Size]" --output textNo output means nothing is running. Anything listed is a cost you can still delete.
The nuclear option: if you are done with the account entirely, closing it (from the root user) stops all charges. AWS keeps a short recovery period after closure. It is the cleanest end to a learning account, but you will lose everything in it.
"I deleted the server, so I am done." Deleting an instance does not delete the EBS volume if it was configured to stay, its snapshots, its Elastic IP, its load balancer or its logs. Check the whole list above, not only the thing you remember.
Architect Decisions: Setting Up Safely#
| Decision | Choose | Why |
|---|---|---|
| Who signs in for daily work? | An admin identity (IAM Identity Center for teams, an IAM user with MFA for a lone learner), never root | Root has unlimited power and cannot be restricted |
| How does the CLI authenticate? | SSO, or aws login, or CloudShell. Access keys only as a last resort | Temporary credentials limit the damage of a leak |
| Free plan or Paid plan while learning? | Free plan | It cannot create a surprise bill |
| How many accounts? | One for this course. Many in real companies (Chapter 8) | Accounts are the strongest isolation boundary |
| Where do I run commands? | CloudShell to start, your laptop CLI when you want your own tools | CloudShell needs no setup and no stored credentials |
| How do I find what to delete? | A consistent tag (Lab=chNN) and templates for anything bigger than a few resources | You cannot delete what you cannot find |
| What is the first thing to create? | A budget with alerts, then Cost Explorer | Warnings before spending, history from day one |
Traps: Mistakes That Cost Marks and Money#
Access keys in code. Pasting an access key into a script and pushing it to a public Git repository is the classic way accounts get hijacked. Bots find such keys within minutes. Never put keys in code, files or chat. Use temporary credentials, and roles for programs running on AWS.
Confusing the account root user with an IAM user. "Root user" is the account owner identity from the sign-up email. An "IAM user" is something you create. A common exam question: "Which identity should be used for everyday tasks?" Answer: not the root user.
Thinking the budget protects you. It only warns, and the data is delayed. Read the email, act the same day, and delete resources.
Working in the wrong Region. A Mumbai bucket, a Virginia server and a Frankfurt database make a confusing lab. Set the Region once, check it every time.
Your account security checklist (print it): root MFA on, with a backup device. Root access keys: none. Alternate contacts set. Daily work with a non-root identity that has MFA. No long-lived access keys in files or code. Budget alert active. CloudTrail records are on by default for 90 days of management events (Chapter 36 extends this).
4.9 Hands-on Lab: Secure the Account, Set a Budget, Run Your First Commands#
Time: 45 minutes. Cost: about $0 (an empty S3 bucket for a few minutes). Region: Mumbai (ap-south-1). You need: an email address, a phone, and a card. Skip step 1 if your account already exists.
Step 1. Create the account#
Go to the AWS sign-up page and follow section 4.1. Choose the Free plan and Basic support.
Step 2. Lock the root user#
- Sign in as the root user. Open the account menu (top right) and choose Security credentials.
- Add MFA: choose a passkey or authenticator app. Add a second device as a backup.
- Check that Access keys shows none. Delete any that exist.
- Open Account, add alternate contacts (billing, operations, security), and set an account alias through IAM.
- Open Billing and Cost Management, then Billing preferences, and turn on IAM user and role access to billing information and Free Tier usage alerts.
Step 3. Create your daily admin identity#
- Open IAM, then Users, then Create user. Name it for yourself, for example
maya-admin. - Tick console access, set a password, and attach the managed policy
AdministratorAccess(for this single learning account only). - Sign out of root. Sign in again with the alias URL as
maya-admin. Add MFA to this user too. - From now on, use only this identity. Chapter 7 replaces it with IAM Identity Center.
Step 4. Create the budget#
Follow section 4.3: a monthly cost budget of $10 with your email, then add the 50 percent actual and 100 percent forecast alerts. Also enable Cost Explorer and Cost Anomaly Detection.
Step 5. Open CloudShell and ask "who am I?"#
Make sure the Region menu says Asia Pacific (Mumbai). Click the >_ icon and run:
aws sts get-caller-identity
aws configure list
aws ec2 describe-regions --query "Regions[].RegionName" --output textStep 6. Install the CLI on your computer and sign in#
aws --version
aws login --profile stackcafe-learning # sign in through the browser. No access key needed
aws sts get-caller-identity --profile stackcafe-learningIf aws login is not recognized, update the AWS CLI v2. If you work on a machine with no browser, add --remote to the login command.
Step 7. Create, tag, find and delete a bucket (the cleanup drill)#
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
BUCKET=stackcafe-lab-ch04-$ACCOUNT
aws s3api create-bucket --bucket $BUCKET --region ap-south-1 \
--create-bucket-configuration LocationConstraint=ap-south-1
aws s3api put-bucket-tagging --bucket $BUCKET \
--tagging 'TagSet=[{Key=Lab,Value=ch04},{Key=Project,Value=stackcafe}]'
aws s3api get-bucket-tagging --bucket $BUCKET # confirm the tags are there
aws s3 ls | grep stackcafe-lab # find it
aws s3 rb s3://$BUCKET # delete it (the bucket must be empty)
aws s3 ls | grep stackcafe-lab || echo "Clean: nothing left"Step 8. Run the sweep#
Run the sweep script from section 4.8. If it prints nothing, you have no running servers anywhere.
What you should see
Step 5 prints your 12-digit account ID and an ARN ending in your identity (for example user/maya-admin or assumed-role/... in CloudShell). Step 6 prints the same account ID, with an ARN that reflects how you signed in. Step 7 shows the two tags, lists the bucket, then prints "Clean: nothing left". If bucket creation fails with BucketAlreadyExists, the name was taken: add a random number to it. If it fails with IllegalLocationConstraintException, you forgot the --create-bucket-configuration line.
In the Billing console, Budgets should show your monthly budget, and Free Tier should show your credit balance. Do not worry if cost graphs are empty, as data appears after a day.
Cleanup checklist: the lab bucket is already deleted in step 7. Keep the budget, the MFA devices and the admin user: you need them for the rest of the course. Nothing else was created.
Cheat Sheet#
| Topic | Remember |
|---|---|
| Root user | MFA on (plus a backup), no access keys, almost never used. Use an admin identity for daily work |
| Free plan | Up to $200 credits, 6 months or until used. Cannot create a surprise bill. NAT gateways, load balancers, databases drain credits |
| Budget | Alerts only. Not a hard stop. Billing data is delayed. Create it first |
| CLI sign-in | SSO, then aws login, then CloudShell. Access keys last |
| Who am I? | aws sts get-caller-identity |
| Six ways | Console, CLI, CloudShell, SDK, infrastructure as code, raw API. All are API calls |
| Tags | Project, Environment, Owner, CostCenter, Lab. Activate cost allocation tags in Billing |
| ARN | arn:partition:service:region:account:resource |
| Cleanup | Tag, delete in reverse order, sweep every Region, check Cost Explorer daily |
DAY ONE sign up > root MFA (x2) > alternate contacts > no root keys > admin identity > budget > Cost Explorer
DAILY console to explore | CloudShell for commands | CLI with SSO or `aws login` | tag everything | clean up
CHECK Region menu first | aws sts get-caller-identity | Cost Explorer | sweep script
FREE? credits yes | always-free allowances yes | NAT gateway, ALB, EKS, RDS, public IPv4: NO
NEVER root for daily work | access keys in code | trusting a budget to stop spendingQuick Recap#
- An AWS account is the basic boundary for security and billing. The root user owns it and must be locked down with MFA (and a backup), have no access keys, and be used almost never.
- Do daily work with a separate admin identity with MFA.
- The Free plan gives up to $200 in credits for up to 6 months and cannot create a surprise bill. Some services (NAT gateways, load balancers, EKS, databases, public IPv4) use credits fast.
- A budget sends alerts. It does not stop spending, and billing data is delayed.
- CloudShell is a free, signed-in terminal. For your own computer, install CLI v2 and sign in with SSO or
aws login, not long-lived keys. aws sts get-caller-identitytells you who and where you are.- The console, CLI, SDK, IaC and raw requests are six doors to one API.
- Tag and name everything. Delete the same day. Sweep every Region.
- The 25-service map is your index for the rest of the course.
Practice Section A: Certification-Style Scenarios (10)#
Click Show answer to reveal each answer. Try before you open it. Aim for 9 or more.
Q1. A company has just created a new AWS account. What should be done first to protect the root user?
A. Create access keys for the root user
B. Enable multi-factor authentication (MFA) on the root user
C. Share the root password with the team
D. Use the root user for daily administration
Show answer
B. Enable MFA on root, never create root access keys, and use a separate identity for daily work.
Q2. Which identity should be used for everyday administrative tasks in an AWS account?
A. The root user
B. An IAM identity (or Identity Center user) with only the permissions it needs, protected by MFA
C. A shared account used by everyone
D. An anonymous user
Show answer
B. The root user is reserved for the few tasks that require it. Daily work uses a limited, MFA-protected identity.
Q3. A student wants to experiment with AWS without risking an unexpected bill. Which option fits best?
A. A Paid plan with no budget
B. The Free plan on a new account, which uses credits and cannot incur charges
C. Using the root user
D. Running everything in many Regions
Show answer
B. The Free plan on new accounts provides credits for up to 6 months and does not charge, ending when credits or time run out.
Q4. A team creates an AWS Budget with an email alert at 100 percent. The budget is reached on Friday night. What happens?
A. AWS automatically stops all resources
B. AWS closes the account
C. The team receives a notification, but resources keep running and spending continues
D. AWS refunds the overspend
Show answer
C. A budget alert is a notification. It does not stop resources unless you also configure a budget action, and even those depend on delayed billing data.
Q5. A developer needs to run AWS CLI commands from a laptop. Which approach is the most secure?
A. Create a long-lived access key for the root user
B. Sign in with IAM Identity Center (SSO) or aws login to get temporary credentials
C. Save an access key in the source code
D. Email credentials to the laptop
Show answer
B. Temporary credentials expire automatically, which limits the damage of a leak. Long-lived keys, and especially root keys, should be avoided.
Q6. Which AWS tool provides a browser-based terminal that is already authenticated and has the AWS CLI installed?
A. AWS CloudTrail
B. AWS CloudShell
C. AWS Config
D. AWS Artifact
Show answer
B. CloudShell opens from the console, uses your console credentials and includes the CLI and common tools.
Q7. Which feature lets a company see how much each project spends, after the right setup?
A. Resource tags activated as cost allocation tags
B. Larger instance sizes
C. Security groups
D. Availability Zones
Show answer
A. Tags such as Project and CostCenter, once activated for cost allocation, appear in Cost Explorer and billing reports.
Q8. What does the following identifier represent? arn:aws:ec2:ap-south-1:123456789012:instance/i-0abc123
A. An S3 bucket in any Region
B. An EC2 instance in the Mumbai Region of account 123456789012
C. An IAM user
D. A CloudFront distribution
Show answer
B. An ARN reads: partition, service (ec2), Region (ap-south-1), account ID, then resource type and ID.
Q9. Which statement about the AWS Management Console, CLI and SDKs is correct?
A. They use completely different back ends
B. They all ultimately call the same AWS APIs
C. Only the console can create resources
D. Only the SDK checks permissions
Show answer
B. Every tool sends signed API requests. IAM checks permissions the same way regardless of the tool.
Q10. A lab left a NAT gateway and a load balancer running over a weekend, although the instances were deleted. Why was the account still billed?
A. NAT gateways and load balancers are charged by the hour while they exist, even with no instances
B. Deleted instances keep charging
C. Budgets create charges
D. CloudShell charges per command
Show answer
A. Those resources have hourly charges independent of servers. That is why every lab ends with a cleanup checklist.
Practice Section B: Interview and Solution Design Questions (10)#
There is no single multiple-choice answer. Say your answer out loud first, then open the model answer. Interviewers care about clear reasoning and trade-offs.
I1. You have just been given a brand-new AWS account. What do you do in the first hour, and why?
Show model answer
I protect the root user first: strong unique password, MFA with a backup device, no access keys, alternate contacts set. Then I create a non-root admin identity with MFA (or set up IAM Identity Center) and stop using root. Next I turn on billing access for that identity, create a budget with alerts and enable Cost Explorer and anomaly detection, so spending is visible from day one. Then I choose a default Region and a tagging convention. The order matters: reduce the worst risk (account takeover), then the next risk (cost), then organize.
I2. Why should the root user not be used for daily tasks?
Show model answer
It has unrestricted power and cannot be limited by IAM policies, SCPs aside, so any mistake or compromise has the maximum blast radius. Its activity is harder to attribute to a person, and its credentials are the highest-value target for attackers. A limited identity with MFA gives the same convenience with a fraction of the risk. Root stays for the small set of tasks that require it, such as changing the account email or closing the account.
I3. A teammate pasted an AWS access key into a public GitHub repository. What do you do?
Show model answer
Act immediately: deactivate and then delete the key in IAM, so it stops working. Then review CloudTrail for what the key did, look for unexpected resources (especially large instances in unusual Regions), and delete them. Rotate any other secrets that were reachable. Remove the key from the repository, though history still contains it, so consider it burned. Prevent it next time: use temporary credentials and roles instead of keys, enable secret scanning and pre-commit checks, and apply least privilege so a leaked key cannot do much.
I4. Explain the difference between a budget alert and a spending limit. How would you protect a learning account?
Show model answer
A budget alert notifies you when actual or forecast spend crosses a threshold. It does not stop resources, and billing data is delayed by hours. AWS has no simple global hard cap for a normal paid account. For a learning account I would use the Free plan, where credits are the limit, add a small budget with several thresholds, keep labs tiny, tag them, and clean up daily. For a company I would add budget actions or policies that restrict creating costly resources, plus anomaly detection.
I5. Why do professionals prefer SSO or aws login to access keys for the CLI?
Show model answer
Both give temporary credentials that expire and refresh automatically, so a leaked laptop or log file exposes access for hours rather than forever. Access keys are long-lived secrets that get copied into files, scripts and repositories, and they rarely get rotated. SSO adds central control: a user can be disabled in one place, with MFA and consistent permissions across many accounts. Keys are only acceptable for tools that cannot use anything else, and then with minimal permissions and rotation.
I6. The console, CLI, SDK and CloudFormation all create an S3 bucket. What is the same underneath, and why does it matter?
Show model answer
Each one sends a signed API request to the S3 service, and IAM evaluates the same permissions. It matters because security and auditing are applied at the API level: a policy that denies bucket creation blocks all four, and CloudTrail records the call regardless of how it was made. It also tells me which tool to use: the console to learn, the CLI for quick tasks, the SDK inside applications, and infrastructure as code for repeatable, reviewable environments.
I7. Design a tagging strategy for a company with five teams and three environments.
Show model answer
A small mandatory set: Project or Application, Environment (dev, test, prod), Owner, and CostCenter, with fixed allowed values and consistent case. I would activate them as cost allocation tags, enforce them with tag policies or service control policies so resources cannot be created without them, and apply tags through infrastructure as code so they are never forgotten. Reports by tag then give showback per team and environment, and automation can use tags to find and delete expired resources.
I8. Your bill doubled this month. How do you investigate?
Show model answer
I open Cost Explorer, group by service, then by usage type, Region and tag, and compare with last month to find the line that grew. I check Cost Anomaly Detection for flagged events. Then I look at the cause: often forgotten resources (NAT gateways, load balancers, unattached volumes), data transfer, or a new workload. I use tags to find the owner, fix the cause, and add a budget or alert so the next jump is caught earlier. I also look at CloudTrail if the growth looks like unauthorized use.
I9. What is the difference between a resource's Region, its name, its tags and its ARN, and how do you use each to find what you created?
Show model answer
They solve different problems. The Region and AZ say where a resource lives, which you must know to see it at all in the console. A name is a human label, and not always unique. Tags are searchable metadata for grouping and cost. The ARN is the unique, complete identifier that includes partition, service, Region, account and resource, used in policies and automation. To find everything for one lab I search by a tag across Regions, and use ARNs when writing permissions.
I10. A new colleague asks, "Why not just give everyone the root login to avoid permission problems?" Respond.
Show model answer
Because it removes accountability and maximizes risk. With one shared login nobody can tell who did what, MFA cannot belong to a person, and one phished password gives an attacker the whole account including the ability to remove our backups and close the account. Permission problems are solved by giving each person their own identity and the specific permissions they need, ideally through SSO and groups, and by using Access Analyzer and the policy simulator to find the missing permission. It takes minutes to fix a permission, but a root compromise cannot be undone.
Next up: Chapter 5. AWS Pricing: Become Your Own AWS Calculator (the five-step estimation method, meters and units, Savings Plans versus Spot with break-even math, hidden costs, and worked bills for a serverless and a three-tier StackCafe).