Lesson 252 of 296
AWS IAM
What you will learn
- What AWS is and how accounts and regions are organised
- IAM users, groups, roles and policies
- Reading and writing a policy
- Roles for applications instead of keys
- Least privilege and other IAM best practices
On this page
AWS in one paragraph
Amazon Web Services (AWS) rents computing resources over the internet: servers, databases, storage, queues and hundreds of managed services, paid for by use. It is organised into regions (geographic areas, such as eu-west-2 London and eu-west-1 Ireland), each with several availability zones (AZs): separate data centres with independent power and networking. Spreading an app across two or three AZs protects it from one data centre failing. UK companies often choose eu-west-2 for data location and latency.
The shared responsibility model: AWS secures the cloud itself (buildings, hardware, the virtualisation layer); you secure what you put in it: your IAM permissions, network rules, data encryption choices, operating system patches on EC2, and application code.
IAM: Identity and Access Management
IAM controls who can do what on which resources. Every AWS API call is checked against IAM.
| Concept | Meaning |
|---|---|
| Root user | The account owner's email login. All powers. Lock it away: enable MFA, never use it day to day, never create access keys for it |
| IAM user | A long-term identity for a person or (in the past) an application, with a password and/or access keys |
| Group | A set of users sharing policies |
| Role | An identity without permanent credentials that is assumed temporarily by a service, an application, a user, or another account. Gives temporary credentials |
| Policy | A JSON document listing allowed or denied actions |
For people in organisations, modern practice is IAM Identity Center (single sign-on with temporary credentials) rather than individual IAM users with access keys.
Policies
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadWriteUploadsForThisApp",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::jobprep-uploads/tenants/*"
},
{
"Sid": "SendToEmailQueue",
"Effect": "Allow",
"Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:eu-west-2:123456789012:email-jobs"
}
]
}| Field | Meaning |
|---|---|
Version | The policy language version; always "2012-10-17" (a fixed value, not a date to update) |
Effect | Allow or Deny |
Action | API operations, service:Operation, wildcards allowed (s3:Get*) |
Resource | Which resources, by ARN (Amazon Resource Name) |
Condition | Optional extra rules: source IP, MFA present, tags, time, VPC |
How decisions work: everything is denied by default; an explicit Allow grants access; an explicit Deny anywhere always wins over any Allow.
Policy kinds: identity-based (attached to users, groups, roles), resource-based (attached to a resource, such as an S3 bucket policy or SQS queue policy, naming who may access it), plus organisation-wide guardrails (Service Control Policies) and permission boundaries.
Roles for applications
Never put access keys inside application code, environment files on servers, or images. Give the compute a role:
| Where the code runs | How it gets credentials |
|---|---|
| EC2 | An instance profile (a role attached to the instance) |
| Lambda | The function's execution role |
| ECS / Fargate | The task role (separate from the task execution role used to pull images and read secrets) |
| GitHub Actions | OIDC trust to assume a role (Lesson 251) |
| Another AWS account | Cross-account role assumption |
The AWS SDK finds these temporary credentials automatically and refreshes them; your code just creates clients (new S3Client({ region: "eu-west-2" })).
A role has two parts: a trust policy (who may assume it, for example lambda.amazonaws.com) and permission policies (what it may do).
Best practices
- Least privilege: grant only the actions and resources needed. Start narrow; add when something fails (CloudTrail and IAM Access Analyzer show what is actually used).
- No long-lived access keys where roles or OIDC are possible. If keys must exist, rotate them.
- MFA for all humans; root locked down.
- Separate accounts for production, staging and development (AWS Organizations), so a mistake in dev cannot touch production.
- CloudTrail records every API call: who did what and when, for auditing and incident investigation.
- Watch for over-broad policies:
"Action": "*"and"Resource": "*"together means administrator access.
How to say it in an interview
"IAM decides which identities can perform which actions on which resources. Everything is denied by default, an Allow grants access, and an explicit Deny always wins. Policies are JSON with Effect, Action, Resource and optional Conditions, attached to identities or to resources like bucket policies. Applications never hold access keys: EC2 uses instance profiles, Lambda an execution role, ECS a task role, and CI uses OIDC, all giving temporary credentials the SDK picks up automatically. I follow least privilege, MFA, a locked-down root user, separate accounts per environment and CloudTrail for auditing."
Key words
| Word | Meaning |
|---|---|
| Region / availability zone | A geographic area / a separate data centre within it |
| Shared responsibility | AWS secures the cloud; you secure what you build in it |
| IAM user / role | Long-term identity / temporarily assumed identity |
| Policy | JSON permissions document |
| ARN | Amazon Resource Name: a unique resource identifier |
| Trust policy | Who may assume a role |
| Least privilege | Only the permissions actually needed |
| CloudTrail | A log of all AWS API calls |
Now prove it
This lesson is complete when you pass the quiz and all three practice levels.