IAM: Users, Groups, Roles & Policies
AWS Identity and Access Management (IAM) decides who can sign in to your account and what they are allowed to do. Every request to AWS, whether a click in the console, a CLI command or a call from a Lambda function, is checked by IAM first. Getting IAM right is the single most important part of AWS security.
Identities: who is making the request?
| Identity | What it is | Use it for |
|---|---|---|
| Root user | The account owner, created at sign-up, with unlimited power | Only the few tasks that require it. Protect with MFA. |
| IAM Identity Center user | A person who signs in through the AWS access portal and gets temporary credentials | The recommended way for humans to access AWS |
| IAM user | A long-term identity in one account, with a password and/or access keys | Special cases only, such as an old tool that cannot use roles |
| IAM group | A collection of IAM users that share permissions | Giving the same permissions to many IAM users at once |
| IAM role | An identity with permissions but no password or long-term keys; it is assumed for a short time | AWS services (EC2, Lambda), other accounts, and Identity Center users behind the scenes |
A role is like a prefect's badge: whoever is allowed to wear it gets its powers, but only while wearing it, and the badge can be taken back. When a role is assumed, AWS's Security Token Service (STS) hands out temporary credentials that expire automatically.
Policies: what is allowed?
Permissions are written in policies, which are JSON documents. You attach a policy to a user, group or role (an identity-based policy) or, for some services such as S3, to the resource itself (a resource-based policy, like a bucket policy). This policy lets its holder list one bucket and read the files in it:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListResultsBucket",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::kuza-school-results-2026"
},
{
"Sid": "ReadResultFiles",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::kuza-school-results-2026/*"
}
]
}
Versionis the policy language version. Always use"2012-10-17"; it is not today's date.Statementis a list of rules.Sidis an optional label.EffectisAlloworDeny.Actionnames API operations asservice:Operation. Wildcards such ass3:Get*are allowed but should be used carefully.Resourceis the ARN the statement applies to. Listing applies to the bucket ARN, while reading applies to objects, hence the/*.Condition(optional) adds rules such as "only with MFA" or "only from this IP range".
How IAM decides: evaluation logic
For each request, IAM gathers every policy that applies and follows three rules, in this order:
- Explicit deny wins. If any applicable policy says
Denyfor this action and resource, the request is denied. Nothing can override it. - Explicit allow. Otherwise, if some policy says
Allow, the request is allowed (as long as no organisation-level guardrail or permissions boundary blocks it). - Implicit deny. If nothing allows it, it is denied. A new IAM user or role with no policies can do nothing.
Explicit denies are useful as guardrails. This statement blocks deleting result files unless the person signed in with MFA, even if another policy allows s3:*:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "NoDeleteWithoutMFA",
"Effect": "Deny",
"Action": "s3:DeleteObject",
"Resource": "arn:aws:s3:::kuza-school-results-2026/*",
"Condition": {
"BoolIfExists": { "aws:MultiFactorAuthPresent": "false" }
}
}
]
}
Least privilege
Least privilege means giving each identity only the permissions it needs for its job, and nothing more. A teacher who uploads marks does not need to delete databases. Start narrow and add permissions when a real need appears, not the other way round. AWS managed policies such as ReadOnlyAccess are a convenient starting point, and IAM Access Analyzer can generate a tighter policy from the actions an identity actually used in CloudTrail logs.
Roles for AWS services
Your code running on AWS should never contain access keys. Instead, give the service a role:
- EC2: attach a role through an instance profile. Programs on the instance (the CLI, boto3) pick up temporary credentials automatically and they rotate on their own.
- Lambda: every function has an execution role. To write logs it needs the permissions in the managed policy
AWSLambdaBasicExecutionRole; add a policy for anything else it touches, such as one DynamoDB table.
Each role has a trust policy saying who may assume it. This one lets the EC2 service assume the role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "ec2.amazonaws.com" },
"Action": "sts:AssumeRole"
}
]
}
For a Lambda execution role, the principal would be lambda.amazonaws.com.
Doing it from the CLI
Here is how an administrator might save the read-only results policy above as a customer managed policy and attach it to a role used by the results portal's servers. The JSON output is an example and is shortened:
aws iam create-policy --policy-name ReadSchoolResults \
--policy-document file://read-results.json
aws iam attach-role-policy --role-name results-portal-ec2 \
--policy-arn arn:aws:iam::123456789012:policy/ReadSchoolResults
attach-role-policy prints nothing when it succeeds. To test a policy before relying on it, use the IAM policy simulator in the console.
Attaching AdministratorAccess or "Action": "*" to an application role "just to make it work". If that app is ever compromised, the attacker gets your whole account. Fix the actual missing permission instead; the error message usually names the exact action that was denied.
Key points
- IAM controls authentication (who you are) and authorisation (what you may do) for every AWS request.
- Use Identity Center for people and roles for AWS services; avoid long-term IAM user keys.
- Policies are JSON with Version, Statement, Effect, Action, Resource and optional Condition.
- Default is deny, an Allow grants access, and an explicit Deny always wins.
- Follow least privilege: grant only what each identity needs.
Tip: use the ← and → keys to move between pages.
