AWS Fundamentals: Regions, AZs & IAM
System Design · Cloud Building Blocks · Basics · 18 min
Know where your AWS resources physically live, how to survive a data center failure, and how IAM decides who may do what.
A map with countries (Regions), each holding three or more walled towns (Availability Zones) and many small outposts (edge locations); at every gate stands a guard holding a rulebook (IAM) who says no unless a rule says yes.
The idea in everyday words
Think of a bank with branches in several cities. Each city (Region) has a few separate buildings (Availability Zones) so a fire in one building doesn't close the bank. Inside, every door has a guard with a list: no name on the list means no entry, and a 'banned' note beats any permission slip.
The map: Regions, Availability Zones, edge locations
- Region = a geographic area with its own name, like
us-east-1(N. Virginia) oreu-west-1(Ireland). Regions are independent: data stays in the Region you choose unless you copy it out. - Availability Zone (AZ) = one or more data centers inside a Region with separate power, cooling and networking, linked to the other AZs by fast, low-latency fiber. Most Regions have three or more.
- Edge location = a small site in many cities, used by CloudFront (CDN), Route 53 (DNS) and Global Accelerator to answer users close to them.
| Layer | Protects you from | Typical use |
|---|---|---|
| Multiple AZs | One data center losing power or network | Default for anything in production |
| Multiple Regions | A whole Region having a bad day, or legal rules | Disaster recovery, global users |
| Edge locations | Distance (latency = waiting time) | Caching static files, DNS |
How to choose a Region: where your users are (latency), where the law says data must live (data residency), which services are available there, and price.
Small but useful fact: AZ names like us-east-1a are shuffled per account, so your 1a may be my 1b. Use AZ IDs like use1-az1 when two accounts must agree on the same physical AZ.
The big rule: spread across at least two AZs. Load balancers, Auto Scaling groups, RDS Multi-AZ and DynamoDB/S3 (which replicate across AZs for you) all build on this.
Accounts, Organizations and the shared responsibility model
An AWS account is a container for resources and a hard security and billing boundary. Real companies use many accounts: prod, staging, dev, security, logs. A mistake in dev can't touch prod if they are different accounts.
AWS Organizations groups accounts into a tree of OUs (organizational units). Service Control Policies (SCPs) set guardrails like "nobody in this OU may leave the approved Regions". SCPs never grant anything; they only cap what IAM can allow. IAM Identity Center gives humans single sign-on into all accounts.
Shared responsibility: AWS secures the cloud itself; you secure what you put in it.
| AWS handles | You handle | |
|---|---|---|
| EC2 | Buildings, hardware, hypervisor | OS patches, firewall rules, your app, data |
| Lambda | All of the above + OS + runtime patching | Your code, its permissions, data |
| S3 | Storage hardware, durability | Bucket policies, encryption choices, who has access |
The more managed the service, the less you patch. But access control and data are always yours.
IAM: users, roles and policies
IAM (Identity and Access Management) answers: who (a principal) can do what (an action) on which thing (a resource), under what conditions.
- Root user: the email that created the account. Turn on MFA, lock it away, never use it day to day.
- IAM user: a named identity with long-term credentials. Avoid for people (use Identity Center) and avoid long-lived access keys.
- IAM role: an identity anyone allowed can assume to get temporary credentials from STS (Security Token Service). EC2 instances, Lambda functions and ECS tasks use roles. Prefer roles everywhere.
- Policy: a JSON document of statements. Each statement has
Effect,Action,Resourceand optionalCondition.
{
"Version": "2012-10-17",
"Statement": [
{ "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::photos/*" },
{ "Effect": "Deny", "Action": "s3:*", "Resource": "arn:aws:s3:::photos/private/*" }
]
}
Identity-based policies attach to a user/role ("what can I do?"). Resource-based policies attach to a resource, like an S3 bucket policy ("who can touch me?").
Least privilege = grant only the actions and resources a job needs, then widen if something breaks. "Action": "*" on "Resource": "*" is a red flag in any review. IAM Access Analyzer can suggest tighter policies from real usage.
A real call from code (boto3, shown here, not runnable in the browser):
import boto3
sts = boto3.client("sts")
creds = sts.assume_role(RoleArn="arn:aws:iam::111122223333:role/ReadPhotos",
RoleSessionName="report-job")["Credentials"]
s3 = boto3.client("s3", aws_access_key_id=creds["AccessKeyId"],
aws_secret_access_key=creds["SecretAccessKey"],
aws_session_token=creds["SessionToken"])
How AWS decides: explicit deny > allow > implicit deny
Every API call is checked against all policies that apply. Inside one account, the core logic is three rules:
- Start at deny. Nothing is allowed by default (an implicit deny).
- If any matching statement says
Deny, the answer is deny. Full stop. This is an explicit deny and nothing can override it. - Otherwise, if at least one matching statement says
Allow, the answer is allow.
Order of statements does not matter. A Deny written last still beats an Allow written first.
Matching uses wildcards: * matches any run of characters and ? matches one character. So s3:Get* matches s3:GetObject and s3:GetBucketPolicy. Action names are case-insensitive; resource ARNs are case-sensitive.
def decide(statements, action, resource):
allowed = False
for effect, act, res in statements:
if act in (action, "*") and res in (resource, "*"):
if effect == "Deny":
return "explicit deny"
allowed = True
return "allow" if allowed else "implicit deny"
rules = [("Allow", "s3:GetObject", "*"), ("Deny", "*", "secret.txt")]
print(decide(rules, "s3:GetObject", "cat.jpg"))
print(decide(rules, "s3:GetObject", "secret.txt"))
print(decide(rules, "s3:PutObject", "cat.jpg"))
Beyond one policy: not every layer combines the same way. This is a classic exam trap.
| Situation | What must say Allow | Example |
|---|---|---|
| Same account: identity policy + resource policy | Either one is enough (they combine as a union) | A bucket policy that names an IAM user lets that user read, even if the user's own policy never mentions S3 |
| Cross-account access | Both sides: the caller's identity policy in account A and the resource policy (or the role's trust policy) in account B | A role in account A reads a bucket in account B |
| Guardrails: SCPs, permissions boundaries, session policies | Every guardrail that applies must allow. They never grant anything on their own; they only cap | An SCP that blocks a Region beats any Allow inside the account |
In every case an explicit Deny in any policy wins. A few services add their own twists (for example, a KMS key policy must allow access to the key), so check the IAM policy evaluation logic page when the details matter.
Other clouds: GCP has regions and zones with Cloud IAM roles bound to principals; Azure has regions and availability zones with Microsoft Entra ID plus Azure RBAC. Open source: Open Policy Agent (OPA) does policy-as-code the same way.
Step by step
- Setup:
Region us-east-1, three AZs. An ALB has nodes in AZ a, b and c; one EC2 app server per AZ; RDS primary in AZ a with a synchronous standby in AZ b.
- Normal traffic:
Requests 1-3 are spread a → b → c. Every app server writes to the RDS primary in AZ a.
- AZ a fails:
Power is lost in AZ a. Its EC2 instance stops answering the ALB's health checks.
- ALB reacts:
After a few failed checks the ALB marks AZ a's target unhealthy and sends traffic only to AZ b and c. Capacity drops by a third, so the remaining servers must have headroom.
- Database failover:
RDS promotes the standby in AZ b. The DB endpoint (a DNS name) now points to AZ b; this usually takes a minute or two, so the app retries failed writes.
- Result:
Users saw at most a short blip. With a single-AZ design, every request after the failure would have returned 503 until AZ a came back.
Code example
def matches(pattern, text):
# '*' = any run of characters (even none), '?' = exactly one character
p = t = 0
star, mark = -1, 0
while t < len(text):
if p < len(pattern) and pattern[p] in ("?", text[t]):
p += 1
t += 1
elif p < len(pattern) and pattern[p] == "*":
star, mark = p, t # remember the star, try matching nothing first
p += 1
elif star != -1:
p = star + 1 # backtrack: let the star eat one more char
mark += 1
t = mark
else:
return False
while p < len(pattern) and pattern[p] == "*":
p += 1
return p == len(pattern)
def as_list(x):
return x if isinstance(x, list) else [x]
def iam_decision(statements, action, resource):
allowed = False
for s in statements:
action_ok = any(matches(a.lower(), action.lower()) for a in as_list(s["action"]))
resource_ok = any(matches(r, resource) for r in as_list(s["resource"]))
if action_ok and resource_ok:
if s["effect"] == "Deny":
return "ExplicitDeny" # a matching Deny ends it immediately
allowed = True
return "Allow" if allowed else "ImplicitDeny"
policy = [
{"effect": "Allow", "action": ["s3:Get*", "s3:List*"], "resource": "arn:aws:s3:::photos*"},
{"effect": "Deny", "action": "s3:*", "resource": "arn:aws:s3:::photos/private/*"},
{"effect": "Allow", "action": "dynamodb:PutItem", "resource": "arn:aws:dynamodb:*:*:table/orders"},
]
requests = [
("s3:GetObject", "arn:aws:s3:::photos/cat.jpg"),
("s3:GetObject", "arn:aws:s3:::photos/private/passport.jpg"),
("s3:DeleteObject", "arn:aws:s3:::photos/cat.jpg"),
("dynamodb:PutItem", "arn:aws:dynamodb:us-east-1:111122223333:table/orders"),
("dynamodb:PutItem", "arn:aws:dynamodb:us-east-1:111122223333:table/users"),
]
for action, resource in requests:
print(f"{iam_decision(policy, action, resource):13} {action:18} {resource}")Complexity
- Time: O(S × P × T) worst case: S statements, each wildcard match costs at most pattern length × text length (usually near linear)
- Space: O(L): lower-casing makes copies of the action strings (L = their total length); the matcher itself needs only two pointers and a flag
Interview tips
Say 'I'll deploy across at least two, ideally three, AZs behind a load balancer, with RDS Multi-AZ' before anyone asks about failure.
Explain AZ vs Region in one breath: AZs protect against a data center failure, Regions protect against a regional event or legal requirements.
When security comes up: 'Each service gets its own IAM role with least-privilege policies; no long-lived access keys; humans use SSO.'
Know the evaluation order: implicit deny by default, an explicit deny always wins, otherwise an allow is needed. Then add: 'in one account an identity or resource policy can grant; cross-account needs both; SCPs and boundaries only restrict.'
Mention multi-account with Organizations and SCP guardrails for any company-scale design.
Challenge: IAM Policy Evaluator
Write iam_decision(statements, action, resource) that returns "Allow", "ExplicitDeny" or "ImplicitDeny".
Each statement is {"effect": "Allow" | "Deny", "action": str or list, "resource": str or list}.
A statement matches when any of its action patterns matches action and any of its resource patterns matches resource.
*matches any run of characters (including none);?matches exactly one character. Every other character (even[and]) matches only itself.- Action matching ignores case; resource matching is case-sensitive.
Good news: the starter already contains a working helper matches(pattern, text) that does the wildcard part. Your job is the IAM decision logic: lists, case, Deny beats Allow, and default deny.
Rules: any matching Deny → "ExplicitDeny". Otherwise any matching Allow → "Allow". Otherwise "ImplicitDeny". Statement order must not matter.
Example:
iam_decision([{"effect": "Allow", "action": "s3:GetObject", "resource": "arn:aws:s3:::photos/*"}],
"s3:GetObject", "arn:aws:s3:::photos/cat.jpg") → "Allow"
Solve it in the browser with tests, hints and an AI coach.
Practice problems
- Wildcard Matching (stretch: write the helper yourself) (Hard)
- AWS docs: IAM policy evaluation logic
- AWS docs: IAM security best practices
- AWS Regions and Availability Zones
More in Cloud Building Blocks
Previous: API Design: REST, GraphQL, gRPC · Next: Compute on AWS: EC2, Lambda, ECS/Fargate, EKS