IAM basics: users, groups, roles and policies
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Operations and security
-
Phase 3: SQL Server on AWS
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Up to now you’ve worked as the root user, which is fine for setup and for nothing else. AWS IAM basics cover how you give people and programs only the access they need, using users, groups, roles and the policies that tie them together.
You’ll create a read-only user, watch AWS refuse a write, and then give that user a role that allows one small job. On the way you’ll see how AWS decides “allow” or “deny” for each request.
| Time | You need | By the end you can |
|---|---|---|
| 60 minutes | The laptop setup from Lesson 3 (signed in with aws login --profile saat-root) and a second browser profile or a private window, so you can sign in as a new user. | Create users, groups and roles, read and write simple policies, assume a role from the CLI, and explain the difference between an implicit deny and an explicit deny. |
What it is, in one line
AWS IAM basics: identities (users, groups, roles) get their permissions from policies, and AWS checks those policies on every request.
In Simple Words
Staff badges in an office
In an office, every employee gets their own badge with their photo. That is an IAM user. The badge opens doors based on the team you’re in, like “Accounts team” or “IT team”.
Those are groups.
Some jobs need a special pass for a short time, like the server room key you sign out from security and return in the evening. That is a role: you borrow it, use it, and it stops working after a while.
The rules printed on the wall (“Accounts team: floors 1 and 2, never the server room”) are policies. A “never” rule always beats an “allowed” rule.
Engineer's View
How IAM really works
Every request to AWS carries an identity (who), an action like ssm:PutParameter (what) and a resource ARN (on what). IAM collects every policy that applies and evaluates them, starting from a default answer of deny. An Allow statement can open the door, but an explicit Deny anywhere shuts it again, no matter what else says Allow.
A policy is a JSON document with Effect, Action, Resource and an optional Condition. You can attach AWS managed policies (like ReadOnlyAccess), customer managed policies you write yourself, or inline policies that live inside a single identity.
A role comes with two policies: a trust policy saying who may assume it and a permissions policy saying what it can do. When you assume a role through STS you get temporary credentials (an access key, a secret and a session token) that expire, after one hour by default. Apps on EC2 and Lambda use roles like this, and admins should too.
Every identity has an ARN, for example arn:aws:iam::123456789012:user/priya.dev. A role session looks like arn:aws:sts::123456789012:assumed-role/lab-ssm-writer/priya-test, which means CloudTrail records both the role and the person using it.
How it works, step by step
This is how the pieces fit together in the lab you’re about to build.
1Create a group with policies
lab-readers gets ReadOnlyAccess (it can look at everything and change nothing) and SignInLocalDevelopmentAccess (which aws login needs from the CLI).
2Add a user to the group
priya.dev gets a console password and inherits whatever the group can do. If a group can carry the policy, don’t attach it to a single user.
3Create a role for one extra job
lab-ssm-writer trusts only priya.dev, and all it can do is write parameters under /lab/ in Systems Manager Parameter Store.
4Assume the role when needed
For most of the day Priya stays read-only. When she has to write a parameter, she assumes the role, does the job with temporary credentials and then drops it.
Each request in those steps goes through the same decision. It’s worth learning this picture well, because it explains nearly every “Access Denied” you’ll run into.
At work this has two consequences. “I attached AdministratorAccess and it’s still denied” usually means there’s a Deny somewhere else, in a service control policy, a permission boundary or a resource policy. And taking away an Allow isn’t the same as adding a Deny, because removing the Allow only helps if nothing else allows the action.
✅ Checkpoint: You can name the four building blocks and explain what happens when one policy allows an action and another one explicitly denies it.
Hands-on lab: AWS IAM basics with a user, a group and a role
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
Run everything in PowerShell from C:\aws-lab. The policy files are written with Set-Content deliberately, because Out-File in Windows PowerShell 5.1 saves UTF-16, and the CLI can’t read that as JSON.
1Sign in as root and note the account number
Run this:
aws login --profile saat-root
$env:AWS_PROFILE = 'saat-root'
$acct = aws sts get-caller-identity --query Account --output text
$acctYou should see your 12-digit account number, something like:
1234567890122Give the account a sign-in alias
Choose a name nobody else in the world has taken, for example saatlab-yourname, and run:
aws iam create-account-alias --account-alias saatlab-yourname
aws iam list-account-aliases --query 'AccountAliases[0]' --output textFrom now on your IAM users sign in at https://saatlab-yourname.signin.aws.amazon.com/console.
3Create the group and attach two AWS managed policies
Paste this whole block:
aws iam create-group --group-name lab-readers
aws iam attach-group-policy --group-name lab-readers --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess
aws iam attach-group-policy --group-name lab-readers --policy-arn arn:aws:iam::aws:policy/SignInLocalDevelopmentAccess
aws iam list-attached-group-policies --group-name lab-readers --query 'AttachedPolicies[].PolicyName' --output textThe last command should print:
ReadOnlyAccess SignInLocalDevelopmentAccess4Create the user with a console password
Paste this whole block. It creates a random first password that has to be changed at the first sign-in:
aws iam create-user --user-name priya.dev --tags Key=course,Value=saatvedha-aws Key=lesson,Value=05 --query User.Arn --output text
aws iam add-user-to-group --user-name priya.dev --group-name lab-readers
$pw = 'Lab-' + [guid]::NewGuid().ToString('N').Substring(0,16) + '!a1'
aws iam create-login-profile --user-name priya.dev --password $pw --password-reset-required --query LoginProfile.UserName --output text
"First password: $pw"You should see something like this:
arn:aws:iam::123456789012:user/priya.dev
priya.dev
First password: Lab-3f9c1a7e2b4d5c60!a15Create the role and its two policies
Paste this whole block:
@"
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::$($acct):user/priya.dev" },
"Action": "sts:AssumeRole"
}]
}
"@ | Set-Content trust.json
@"
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["ssm:PutParameter", "ssm:GetParameter", "ssm:DeleteParameter"],
"Resource": "arn:aws:ssm:ap-south-1:$($acct):parameter/lab/*"
}]
}
"@ | Set-Content ssm-writer.json
$roleArn = aws iam create-role --role-name lab-ssm-writer --assume-role-policy-document file://trust.json --tags Key=course,Value=saatvedha-aws Key=lesson,Value=05 --query Role.Arn --output text
aws iam put-role-policy --role-name lab-ssm-writer --policy-name write-lab-parameters --policy-document file://ssm-writer.json
$roleArnYou should see something like this:
arn:aws:iam::123456789012:role/lab-ssm-writer6Sign in as Priya from the CLI
Run this and sign in as priya.dev in the browser window that opens. Use the alias sign-in page, and set a new password when it asks:
Remove-Item Env:AWS_PROFILE
aws login --profile priya
aws sts get-caller-identity --profile priya --query Arn --output textYou should see something like this:
arn:aws:iam::123456789012:user/priya.devIf your browser is already signed in as root, do Priya’s sign-in in a private window.
7Try to write as Priya, then through the role
Paste this whole block:
aws ssm put-parameter --profile priya --name /lab/05/test --type String --value hello
$c = aws sts assume-role --profile priya --role-arn $roleArn --role-session-name priya-test --query Credentials --output json | ConvertFrom-Json
$env:AWS_ACCESS_KEY_ID = $c.AccessKeyId; $env:AWS_SECRET_ACCESS_KEY = $c.SecretAccessKey; $env:AWS_SESSION_TOKEN = $c.SessionToken
aws sts get-caller-identity --query Arn --output text
aws ssm put-parameter --name /lab/05/test --type String --value helloYou should see something like this:
An error occurred (AccessDeniedException) when calling the PutParameter operation: User: arn:aws:iam::123456789012:user/priya.dev is not authorized to perform: ssm:PutParameter on resource: arn:aws:ssm:ap-south-1:123456789012:parameter/lab/05/test because no identity-based policy allows the ssm:PutParameter action
arn:aws:sts::123456789012:assumed-role/lab-ssm-writer/priya-test
{
"Version": 1,
"Tier": "Standard"
}The first write failed with an implicit deny, meaning nothing allowed it. Then the role session worked, and its ARN shows both the role name and the session name. Since there was no --profile and no AWS_PROFILE, the CLI picked up the three environment variables.

8Ask IAM before you try
Run this as root. The simulator lets you test permissions without changing anything:
aws iam simulate-principal-policy --profile saat-root --policy-source-arn "arn:aws:iam::$($acct):user/priya.dev" --action-names ec2:DescribeInstances ec2:TerminateInstances --query 'EvaluationResults[].[EvalActionName,EvalDecision]' --output textYou should see this:
ec2:DescribeInstances allowed
ec2:TerminateInstances implicitDeny✅ Checkpoint: Priya was denied with “no identity-based policy allows”, the role session wrote /lab/05/test, and the simulator shows implicitDeny for terminating instances. Leave everything in place for the break lab, which ends with the cleanup.
Break It, Then Fix It
Here are two IAM errors you’ll probably meet in your first month at work.
1Break it: a trust policy pointing at a user that doesn’t exist
Copy trust.json, put a typo in the user name, and try to use it:
(Get-Content trust.json) -replace 'priya.dev','priya.dv' | Set-Content trust-typo.json
aws iam update-assume-role-policy --profile saat-root --role-name lab-ssm-writer --policy-document file://trust-typo.jsonYou’ll get this error (something like this):
An error occurred (MalformedPolicyDocument) when calling the UpdateAssumeRolePolicy operation: Invalid principal in policy: "AWS":"arn:aws:iam::123456789012:user/priya.dv"When you save the policy, IAM checks that any user or role named as a principal actually exists. Fix: correct the ARN. You’ll see the same error when someone deletes a user and later tries to edit a trust policy that still names that user.
2Break it: an explicit deny beats an allow
Add a Deny for deleting parameters to the role, then try a delete using the role session from step 7:
@'
{ "Version": "2012-10-17", "Statement": [{ "Effect": "Deny", "Action": "ssm:DeleteParameter", "Resource": "*" }] }
'@ | Set-Content deny-delete.json
aws iam put-role-policy --profile saat-root --role-name lab-ssm-writer --policy-name deny-delete --policy-document file://deny-delete.json
Start-Sleep -Seconds 10
aws ssm delete-parameter --name /lab/05/testYou’ll get this error (something like this):
An error occurred (AccessDeniedException) when calling the DeleteParameter operation: User: arn:aws:sts::123456789012:assumed-role/lab-ssm-writer/priya-test is not authorized to perform: ssm:DeleteParameter on resource: arn:aws:ssm:ap-south-1:123456789012:parameter/lab/05/test with an explicit deny in an identity-based policy
The role still has the Allow from write-lab-parameters, but the Deny wins anyway. Notice that the change reached the running session within seconds, and that the message tells you which kind of policy did the denying.
To fix it, remove the Deny and then delete the parameter:
aws iam delete-role-policy --profile saat-root --role-name lab-ssm-writer --policy-name deny-delete
Start-Sleep -Seconds 10
aws ssm delete-parameter --name /lab/05/test3Clean up everything from this lesson
Paste this whole block:
Remove-Item Env:AWS_ACCESS_KEY_ID, Env:AWS_SECRET_ACCESS_KEY, Env:AWS_SESSION_TOKEN
aws logout --profile priya
$env:AWS_PROFILE = 'saat-root'
aws iam delete-role-policy --role-name lab-ssm-writer --policy-name write-lab-parameters
aws iam delete-role --role-name lab-ssm-writer
aws iam delete-login-profile --user-name priya.dev
aws iam remove-user-from-group --user-name priya.dev --group-name lab-readers
aws iam delete-user --user-name priya.dev
aws iam detach-group-policy --group-name lab-readers --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess
aws iam detach-group-policy --group-name lab-readers --policy-arn arn:aws:iam::aws:policy/SignInLocalDevelopmentAccess
aws iam delete-group --group-name lab-readers
.\Find-LabResources.ps1Keep the account alias, since it costs nothing and you’ll use it again. IAM is global, so the finder script might not list IAM items at all, but aws iam list-users and aws iam list-roles --query "Roles[?starts_with(RoleName,'lab')]" will confirm they’re gone.
✅ Checkpoint: You read an invalid-principal error and an explicit-deny error, fixed both of them, and removed the lab user, group and role.
This happened at work
Who deleted the firewall rule at 3 AM?
This operations team shared a single IAM user, ops-admin, with AdministratorAccess. The password lived on an internal wiki page, six people used it, and a monitoring tool had its access keys as well.
One night, the rule that allowed the payment provider’s IP range vanished from a security group and card payments failed for 50 minutes. CloudTrail showed when it happened and that ops-admin did it from an office IP address, but it had no way of showing which of the six people that was, and nobody could remember.
So the team moved to one identity per person through IAM Identity Center, with read-only rights by default and an admin role that asks for a reason and expires after an hour. The monitoring tool got a role of its own with only the actions it needed. These days every CloudTrail event names a real person, and a monthly check of the credential report catches old keys and unused users.
Common mistakes and troubleshooting
| Mistake | What happens | What to do |
|---|---|---|
| Shared IAM users | Nobody can tell who did what, and people who leave keep their access | One identity per person; roles for elevated work |
| Attaching policies to individual users | Rights drift and nobody can say who has what | Attach to groups (or permission sets in Lesson 6) |
| AdministratorAccess “to save time” | Any mistake or leak has full power | Start read-only and add only the actions that are needed |
| Thinking removing an Allow blocks something | Some other policy still allows it | Use an explicit Deny when something must never happen |
| Policy files saved with Out-File in PowerShell 5.1 | The CLI fails to parse the JSON | Use Set-Content (or -Encoding ascii) |
| Trust policy names a deleted user | MalformedPolicyDocument: Invalid principal | Update or remove the principal, then save again |
Interview questions
Click a question to open it. Each one is worded the way an interviewer might ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. Can you explain in simple words the difference between an IAM user and an IAM role?
Why they ask this: They’re checking your core IAM understanding, because knowing when to use a role instead of a user is the base of good AWS security.
How you might answer: A user is a long-lived identity for one person or app, with a password or access keys. A role has no long-term credentials at all; trusted people or services assume it and get temporary credentials. That’s why I use roles for apps running on AWS and for admin work.
2. Say no policy mentions a certain action at all. Can the user do it or not?
Why they ask this: They want to see you know AWS denies by default, an idea that explains a lot of access problems.
How you might answer: No, they can’t. AWS denies everything by default, so the action only works once some policy explicitly allows it.
3. Your team has 15 developers who need the same permissions. How would you set that up?
Why they ask this: They want to see good admin habits rather than policies stuck onto each person, and they’re also checking you know what groups can’t do.
How you might answer: I’d make a group, attach the policies to it and add the 15 users. When someone joins or leaves, I add or remove them from the group and that’s it. I’d also remember that groups have no credentials, can’t be assumed and can’t be nested inside other groups.
2–5 years experience
4. A user has AdministratorAccess but still gets AccessDenied. Where would you look?
Why they ask this: They want to know you understand the other policy types that can block access, which is what separates people who know IAM from people who only know managed policies.
How you might answer: I’d go looking for an explicit deny somewhere else, maybe a service control policy from AWS Organizations, a permission boundary on the user, a resource-based policy like a bucket or key policy, or a session policy. Often the error message names the type that denied it, and if it doesn’t, I’d check CloudTrail and the policy simulator.
5. How would you explain a trust policy to a new team member?
Why they ask this: They’re checking you understand how roles get assumed, since trust policy mistakes are one of the most common reasons a role doesn’t work.
How you might answer: I’d tell them it’s the policy on the role itself that says who’s allowed to assume it, whether that’s a user, another account or a service like ec2.amazonaws.com. If the trust policy doesn’t match, nobody gets to assume the role, whatever their own permissions say.
6. A developer wants to put access keys on an EC2 instance so their app can read S3. What would you suggest instead?
Why they ask this: They want to see you use roles in real life and not only in theory. Keys left lying on servers are a classic security problem.
How you might answer: I’d create a role trusted by ec2.amazonaws.com with only the S3 actions and buckets the app needs, and attach it to the instance through an instance profile. The SDK picks up temporary credentials from the instance metadata on its own, so there are no keys to leak or rotate.
Senior level
7. You’re asked to clean up IAM in an account that has grown messy over five years. How would you do it without breaking things?
Why they ask this: They’re looking for a safe approach driven by data. Pull access too quickly and apps break, but remove nothing and the risk stays where it is.
How you might answer: I’d begin with the credential report and access advisor data to find unused users, keys and roles by their last-used date. Then I’d move people over to Identity Center, swap user keys in apps for roles, and use IAM Access Analyzer to spot unused permissions and external access. Removal would happen in stages, disabling first and deleting after a waiting period, with the owners told before each step.
8. Walk me through how AWS decides whether a request is allowed when several policies apply across an organization.
Why they ask this: They want to see deep knowledge of the evaluation logic, because senior engineers are expected to debug access problems that span accounts and policy types.
How you might answer: AWS looks at every policy that applies: SCPs and resource control policies from Organizations, resource-based policies, identity-based policies, permission boundaries and session policies. If there’s an explicit Deny anywhere, that’s the end of it. If not, the SCPs, boundaries and session policies all have to allow the action, and an identity or resource policy has to grant it, so what you end up with is the overlap of the limits plus the grants.
Quick quiz
Q1. One policy allows ssm:DeleteParameter and another explicitly denies it. What happens?
- Allowed, because Allow came first
- Denied, because explicit Deny wins
- It depends on which policy is newer
- AWS asks the user
Show answer
B: an explicit Deny always overrides any Allow.
Q2. What does a role’s trust policy control?
- What the role can do
- Who can assume the role
- How long the role exists
- Which Region it works in
Show answer
B: the trust policy names the principals that may assume the role, and the permissions policy covers what it can do.
Q3. What do you get when you assume a role?
- A new password
- Long-term access keys
- Temporary credentials with a session token
- A new IAM user
Show answer
C: STS hands back an access key, a secret key and a session token, all of which expire.
Q4. Priya’s write fails with “because no identity-based policy allows”. What kind of deny is this?
- Explicit deny
- Implicit deny
- Service control policy deny
- Network deny
Show answer
B: nothing allowed the action, so the default deny kicked in.
Q5. Why should you attach policies to groups instead of single users?
- Groups are cheaper
- It keeps permissions consistent and easy to review
- Users can’t have policies
- Groups can be assumed like roles
Show answer
B: a group gives a whole team the same rights and keeps reviews simple.
Quick recap
- Users are long-lived identities, groups bundle permissions together, roles hand out temporary credentials, and policies are the JSON rules behind all of them.
- AWS denies by default. An Allow opens up an action, and an explicit Deny shuts it whatever anything else says.
- A role has a trust policy (who can assume it) and a permissions policy (what it can do).
- The error message tells you which kind of deny you hit: “no identity-based policy allows” (implicit) or “with an explicit deny”.
- In Windows PowerShell 5.1, write JSON files with Set-Content, and clean up users, groups and roles after each lab.
Next lesson
Lesson 6: IAM Identity Center and MFA → Next you’ll set up IAM Identity Center, so you can stop using root for the CLI and sign in as yourself every day.
Further reading: AWS IAM basics
If you want to go further with AWS IAM basics, read Policy evaluation logic and Troubleshoot access denied error messages in the IAM User Guide. The full plan for this course is on the AWS Cloud Administration course page.
