TExcelTAD
Home › AWS Cloud › IAM Users, Groups and Roles

IAM Users, Groups and Roles

AWS Identity and Access Management (IAM) controls who can do what on which resources in your account. It is a global service (not tied to a Region) and it is free.

Every API call to AWS is checked by IAM. Two questions are answered each time:

  1. Authentication: who is calling? (a signed request with credentials)
  2. Authorisation: is this identity allowed to perform this action on this resource? (policies)

The building blocks

Thing What it is Credentials
Root user The account owner, unlimited power Email + password (+ MFA)
IAM user A long-lived identity for one person or app Password for the console, access keys for the API
IAM group A collection of users; attach policies once, all members get them None (groups cannot log in)
IAM role An identity that is assumed temporarily by a user, a service or another account Temporary credentials from STS
Policy A JSON document that allows or denies actions n/a

Tip: For people, AWS recommends IAM Identity Center (single sign-on with temporary credentials) instead of creating IAM users. IAM users with access keys remain common in older setups and for some tools.

Creating them with the CLI

bash
aws iam create-group --group-name developers
aws iam attach-group-policy --group-name developers \
    --policy-arn arn:aws:iam::aws:policy/ReadOnlyAccess
aws iam create-user --user-name grace
aws iam add-user-to-group --user-name grace --group-name developers
aws iam list-groups-for-user --user-name grace --query "Groups[].GroupName"

Sample output of the last command:

text
[
    "developers"
]

Model: effective permissions from groups

A user's permissions are the union of the policies attached to the user directly and to every group they belong to. Groups can't contain other groups.

python · try it yourself
groups = {
    "developers": {"s3:GetObject", "s3:ListBucket", "logs:GetLogEvents"},
    "deployers":  {"lambda:UpdateFunctionCode", "cloudformation:CreateStack"},
    "billing":    {"ce:GetCostAndUsage"},
}
users = {
    "grace": {"groups": ["developers"], "direct": set()},
    "linus": {"groups": ["developers", "deployers"], "direct": {"s3:PutObject"}},
    "ada":   {"groups": ["billing"], "direct": set()},
}

def effective(user):
    perms = set(users[user]["direct"])
    for g in users[user]["groups"]:
        perms |= groups[g]
    return sorted(perms)

for name in users:
    print(f"{name}: {', '.join(effective(name))}")
grace: logs:GetLogEvents, s3:GetObject, s3:ListBucket
linus: cloudformation:CreateStack, lambda:UpdateFunctionCode, logs:GetLogEvents, s3:GetObject, s3:ListBucket, s3:PutObject
ada: ce:GetCostAndUsage

Managing permissions through groups is much easier than per user: when someone changes team you move them to another group instead of editing policies.

Roles and temporary credentials

A role has two policies:

  • a trust policy: who may assume the role (a service like ec2.amazonaws.com, a user, another account);
  • permission policies: what the role can do once assumed.

When a principal assumes a role, AWS STS (Security Token Service) hands out temporary credentials that expire, by default after one hour. Nothing long-lived is stored on the server: an EC2 instance with an attached role gets fresh credentials automatically.

json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "ec2.amazonaws.com" },
    "Action": "sts:AssumeRole"
  }]
}
bash
aws sts assume-role --role-arn arn:aws:iam::123456789012:role/report-reader \
    --role-session-name grace-session

Sample output (shortened):

text
{
    "Credentials": {
        "AccessKeyId": "ASIAEXAMPLETEMPKEY01",
        "SecretAccessKey": "...",
        "SessionToken": "...",
        "Expiration": "2026-03-02T11:15:00+00:00"
    },
    "AssumedRoleUser": {
        "Arn": "arn:aws:sts::123456789012:assumed-role/report-reader/grace-session"
    }
}

Model: assume a role with a trust policy

python · try it yourself
from datetime import datetime, timedelta

roles = {
    "report-reader": {
        "trusted": {"arn:aws:iam::123456789012:user/grace", "ec2.amazonaws.com"},
        "permissions": {"s3:GetObject"},
    },
}

def assume_role(caller, role_name, at, duration_minutes=60):
    role = roles[role_name]
    if caller not in role["trusted"]:
        return f"AccessDenied: {caller} is not trusted by {role_name}"
    expires = at + timedelta(minutes=duration_minutes)
    return f"OK: temporary credentials for {role_name}, expire {expires:%Y-%m-%d %H:%M}"

start = datetime(2026, 3, 2, 10, 15)
print(assume_role("arn:aws:iam::123456789012:user/grace", "report-reader", start))
print(assume_role("ec2.amazonaws.com", "report-reader", start, duration_minutes=360))
print(assume_role("arn:aws:iam::123456789012:user/linus", "report-reader", start))
OK: temporary credentials for report-reader, expire 2026-03-02 11:15
OK: temporary credentials for report-reader, expire 2026-03-02 16:15
AccessDenied: arn:aws:iam::123456789012:user/linus is not trusted by report-reader

Common mistakes

  • Using the root user or one shared admin user for everything: no audit trail of who did what.
  • Putting access keys on EC2 instances or in Lambda code instead of using a role.
  • Forgetting that a role needs both a trust policy and permissions: if either is missing, it doesn't work.

Test yourself

Which IAM identity should an EC2 instance use to read from S3?

  1. The root user
  2. An IAM user with access keys copied to the instance
  3. An IAM role attached to the instance
  4. An IAM group

What does a role's trust policy define?

  1. Which actions the role can perform
  2. Who is allowed to assume the role
  3. The role's password
  4. Which Region the role works in

Can an IAM group contain another group?

  1. Yes, up to 10 levels
  2. No, groups contain only users
  3. Only in AWS Organizations
  4. Only for admins