Back to Blog

AWS IAM Explained: Users, Groups, Roles and Policies

•8 min read
Antara Karmakar
by Antara Karmakar
AWS IAM Explained: Users, Groups, Roles and Policies

You've just bought a large office building. You hold the master key that opens every door, every vault and every server room. Carrying that master key around every day is a bad idea. If you lose it, the whole building is compromised. So you hire a security team that hands out badges to specific people and decides which rooms they can enter and what they can do inside.

On AWS, that security team is Identity and Access Management (IAM).

Whether you deploy EC2 instances, configure VPCs or build serverless applications, IAM is the foundation of your security. It answers one question: who can do what, and on which resources?

In this article I'll walk through the four building blocks of IAM, each with a real-world scenario:

  • Users: the permanent residents
  • Groups: teams of users that share permissions
  • Roles: temporary badges for people, services and other accounts
  • Policies: the rulebook that grants or denies access

Part 1: IAM Users, the Permanent Residents

An IAM user is an identity inside your AWS account. It represents a person (or, in older setups, an application) that works with AWS day to day.

The root user is different. It is created together with the account and has unrestricted access to every service and every resource. That's why you protect it with multi-factor authentication (MFA), lock the credentials away and only use it for the few tasks that really need it.

An IAM user starts with zero permissions. Every action is denied until you explicitly grant it.

IAM users sign in with:

  • a username and password for the AWS Management Console
  • access keys for the AWS CLI and the SDKs

MFA is optional for IAM users, but you should turn it on for every user with console access.

Real-World Use Case: A New Developer

You've just hired a junior developer. They need to deploy frontend code to EC2 instances and upload data to S3 buckets. They should never be able to terminate your production database by accident.

You create an IAM user named dev-alex, give Alex console access and attach permissions for reading and writing EC2 instances and S3 buckets. Nothing else. The production database stays out of reach, because nobody ever granted access to it.

IAM users: the root user is locked away, the IAM user dev-alex starts with zero permissions, gets explicit access to EC2 and S3 and has no access to production databases

For human access in a company with several accounts, AWS today recommends IAM Identity Center instead of individual IAM users. The concepts stay the same: an identity, zero permissions by default and access you grant on purpose.

IAM Infographic

IAM on One Page (No Fluff)

Secure your AWS resources. Our IAM cheat sheet covers roles, policies, and permissions - everything you need for proper access control.

HD quality, print-friendly. Stick it next to your desk.

Privacy Policy
Twice-a-month AWS newsletter, occasional product notes. No spam, no data selling.

Part 2: IAM Groups, Teams That Share Permissions

Managing permissions for one developer is easy. Doing the same for a whole department of developers and database administrators turns into a mess quickly.

An IAM group is a collection of IAM users. You attach permissions to the group, and every user in that group inherits them.

Real-World Use Case: A Growing Startup

You run the cloud infrastructure of a fast-growing startup. There are four teams: frontend developers, backend developers, cloud architects and finance.

Instead of managing permissions per person, you create four groups:

  1. Frontend-Devs: access to the S3 buckets that host the static frontend assets
  2. Backend-Devs: access to DynamoDB, RDS, Aurora and ElastiCache
  3. Cloud-Architects: broad access to EC2, VPCs and Auto Scaling groups
  4. Finance-Team: access to AWS Billing and Cost Explorer only

A new frontend intern starts. You add their IAM user to Frontend-Devs, and they get exactly what the team needs. When the internship ends, you remove them from the group and the access is gone.

IAM groups: a new frontend intern joins Frontend-Devs and inherits access to S3, while Backend-Devs, Cloud-Architects and Finance-Team inherit access to databases, EC2 and VPCs, and billing

Two things to keep in mind:

  • A user can be in several groups and gets the combined permissions of all of them.
  • Groups can't contain other groups, so keep the structure flat.

Part 3: IAM Roles, the Temporary Badges

This is where IAM gets powerful. An IAM role looks similar to a user, but it has no long-term credentials. No password, no permanent access keys.

Instead, a role is assumed by whoever or whatever needs it. When a role is assumed, the AWS Security Token Service (STS) issues short-lived credentials that expire on their own.

Think of a role like a hat. Whoever puts it on gets the powers that come with it. Once they take it off, the powers are gone.

Every role has two parts:

  • a trust policy that says who is allowed to assume the role
  • permission policies that say what the role is allowed to do
IAM roles: AWS STS issues short-lived credentials for a service role used by an EC2 instance to write to S3, a cross-account role used by a developer to read CloudWatch logs in production, and a federated role used by a mobile game player who signs in with Google

Type 1: Service Roles

Service roles are used when one AWS service needs to access another.

You run a frontend application on an EC2 instance, and users can upload profile pictures. The pictures should end up in an S3 bucket.

Storing access keys in the application code or on the server is a serious security risk. Anyone who gets hold of the server or the repository gets the keys too.

Instead, you attach a role to the EC2 instance (through an instance profile). The role works like a temporary pass that tells S3: "This server is allowed to put photos in here." The AWS SDK on the instance picks up the temporary credentials automatically and rotates them for you.

The trust policy of that role allows the EC2 service to assume it:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": { "Service": "ec2.amazonaws.com" },
            "Action": "sts:AssumeRole"
        }
    ]
}

Type 2: Cross-Account Roles

Cross-account roles are used when several AWS accounts need to share resources safely.

Your company has two AWS accounts: one for development and one for production. A developer in the dev account needs to read CloudWatch logs in production.

Instead of creating a second IAM user for them in production, you create a role in the production account that trusts the dev account. The developer assumes that role and gets temporary, read-only access to the logs.

With the AWS CLI, assuming the role looks like this:

aws sts assume-role \
  --role-arn arn:aws:iam::<prod-account-id>:role/ReadProdLogs \
  --role-session-name alex-debugging

The response contains temporary credentials that are only valid for a limited time (one hour by default).

Type 3: Federated Roles

Federated roles grant access to users who sign in outside of AWS.

You play a mobile game and tap "Sign in with Google". Behind the scenes, the game needs to save your high score in the company's database. The developers won't create an IAM user for each of their millions of players.

Instead, AWS trusts Google's sign-in. After you've signed in, a service like Amazon Cognito exchanges the Google token for temporary credentials of a federated role. Your phone gets just enough permission to save your game progress, and nothing more.

The same mechanism works for CI/CD pipelines. GitHub Actions can authenticate to AWS with OIDC and assume a role, so you never have to store access keys as repository secrets.

If you want to learn more about roles, read Get to Grips with AWS IAM Roles.

Part 4: IAM Policies, the Rulebook

Users, groups and roles are empty shells. They can't do anything until you give them permissions. The document that contains those permissions is an IAM policy.

Policies are JSON documents. Each statement defines:

  • the effect: Allow or Deny
  • the actions, e.g. s3:PutObject
  • the resources the actions apply to
  • optional conditions under which the statement applies

When AWS evaluates a request, everything is denied by default. An Allow opens access, and an explicit Deny always wins over any Allow.

IAM policies: identity-based policies are attached to users, groups or roles and come as AWS managed, customer managed or inline policies, while resource-based policies like S3 bucket policies are attached to the resource itself

Type 1: AWS Managed Policies

AWS managed policies are prebuilt policies that AWS creates and maintains.

You need to give a developer full access to DynamoDB, fast. You attach the AWS managed policy AmazonDynamoDBFullAccess and you're done.

It's quick and easy, but managed policies often grant more than you actually need.

Type 2: Customer Managed Policies

Customer managed policies are policies you write yourself. You decide exactly which actions on which resources are allowed.

You want to follow the principle of least privilege. Instead of full S3 access, a developer should only be able to read objects from a single bucket named financial-data-prod:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::financial-data-prod/*"
        }
    ]
}

You own this policy, can attach it to several users, groups or roles and can update it at any time. For a hands-on walkthrough of writing these, read AWS IAM Policies: A Practical Approach.

Type 3: Inline Policies

Inline policies are embedded directly in a single user, group or role. They are deleted together with that identity.

They are rarely the right choice today. They make sense when a policy has a strict one-to-one relationship with an identity and must never be attached to anything else.

Identity-Based vs. Resource-Based Policies

This distinction matters once you build anything beyond a single account.

Everything so far, attaching a policy to a user, group or role, is an identity-based policy. It defines what that identity can do.

A resource-based policy is attached to the resource itself. It defines who can access that resource.

Take an S3 bucket that stores public website assets. You attach a bucket policy that says: "Anyone on the internet may run s3:GetObject on the files in this bucket." You don't need to know who the users are. The bucket decides on its own.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-website-assets/*"
        }
    ]
}

For this policy to work, you have to turn off Block Public Access, which is on by default. You find it in the Permissions tab of the bucket, and there is an account-wide setting as well. For most websites, putting CloudFront in front of a private bucket is the safer option, because the bucket itself never becomes public.

How It All Fits Together

A secure, scalable AWS setup uses all four building blocks together:

  1. Lock away the root user and protect it with MFA.
  2. Create an identity for every person on your team and organize them in groups, so permissions follow the team and not the individual.
  3. Whenever an application, an AWS service like EC2 or an external pipeline needs access, let it assume a role. Never hand out permanent access keys.
  4. Write least-privilege customer managed policies, so that if a breach happens, the blast radius stays small.

IAM is more than a security checkbox. Set it up right from day one and your cloud environment stays secure while it grows.

See you on the other side, happy learning!