Skip to content
Kuza Ndoto Academy

IAM: Users, Groups, Roles & Policies

Beginner → IntermediateChapter 2 · Page 6 of 305 min readUpdated 15 Nov 2026

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?

IdentityWhat it isUse it for
Root userThe account owner, created at sign-up, with unlimited powerOnly the few tasks that require it. Protect with MFA.
IAM Identity Center userA person who signs in through the AWS access portal and gets temporary credentialsThe recommended way for humans to access AWS
IAM userA long-term identity in one account, with a password and/or access keysSpecial cases only, such as an old tool that cannot use roles
IAM groupA collection of IAM users that share permissionsGiving the same permissions to many IAM users at once
IAM roleAn identity with permissions but no password or long-term keys; it is assumed for a short timeAWS 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/*"
    }
  ]
}
  • Version is the policy language version. Always use "2012-10-17"; it is not today's date.
  • Statement is a list of rules. Sid is an optional label.
  • Effect is Allow or Deny.
  • Action names API operations as service:Operation. Wildcards such as s3:Get* are allowed but should be used carefully.
  • Resource is 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".
Group: teachers amina otieno Role: notes-app assumed by Lambda A trust policy says who may assume the role Policy Allow s3:GetObject Policy Allow dynamodb:PutItem S3 bucket school results DynamoDB table Notes attached attached allows allows Everything is denied by default until a policy allows it. An explicit Deny always wins.
Figure 1. Identities (users in groups, and roles) get permissions from attached policies, and policies name the actions allowed on specific resources.

How IAM decides: evaluation logic

For each request, IAM gathers every policy that applies and follows three rules, in this order:

  1. Explicit deny wins. If any applicable policy says Deny for this action and resource, the request is denied. Nothing can override it.
  2. Explicit allow. Otherwise, if some policy says Allow, the request is allowed (as long as no organisation-level guardrail or permissions boundary blocks it).
  3. 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
{ "Policy": { "PolicyName": "ReadSchoolResults", "Arn": "arn:aws:iam::123456789012:policy/ReadSchoolResults", "DefaultVersionId": "v1", "AttachmentCount": 0 } }
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.

Common mistake

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.
Up next · Security & AccessSecurity Best PracticesMFA, least privilege, access keys and protecting secrets.
→

Tip: use the ← and → keys to move between pages.