AWS IAM Tutorial for Beginners: Users & Roles

AWS IAM Tutorial for Beginners: Users, Groups, Roles and Policies

AWS Identity and Access Management — IAM — is the service that decides who can do what in your AWS account. Every EC2 instance you launch, every file you read from S3, every deployment your pipeline runs: IAM either allowed it or it did not. Beginners often treat IAM as an administrative chore to rush past, and then spend days debugging AccessDenied errors, or worse, discover that a leaked access key gave a stranger the run of their account. This tutorial treats IAM as the foundation it is.

You will build a working IAM setup from scratch: lock down the root user, create users and groups, write JSON policies, hand out temporary credentials through roles, and set up the hygiene habits that keep an account safe. Every step uses the AWS CLI as well as the console, because the CLI is what you will use in real pipelines. You need an AWS account to follow along; the steps that cost nothing are flagged, and IAM itself is a service you use with no additional charge.

What Is AWS IAM?

IAM is the AWS service that controls authentication — who is signed in — and authorisation — what they are allowed to do. When a request reaches AWS, IAM checks the identity making it, finds the policies attached to that identity, and decides whether the requested action on the requested resource is allowed. If no policy allows it, the request is denied. That default-deny behaviour is the single most important fact in this tutorial: a brand-new IAM user has no permissions to do anything, and every permission they ever get comes from a policy somebody attached.

IAM is built from four components. Users are identities for individual people or applications, each with its own credentials. Groups are collections of users that share permissions, so you attach a policy once to the group instead of once per person. Roles are identities that provide temporary credentials, assumed by users, applications or AWS services. Policies are JSON documents that define the permissions themselves — which actions are allowed or denied, on which resources, and under which conditions. Everything else in IAM — MFA devices, access keys, permission boundaries, identity providers — supports one of those four.

Two design choices shape how you should use IAM. First, IAM is global rather than regional: users, groups, roles and policies exist once per account, not once per Region, so a policy you write in one Region applies everywhere. Second, IAM is eventually consistent, because AWS replicates IAM data across its data centres — a policy change usually takes effect within seconds, but in rare cases a change can take a little while to reach every endpoint, so do not assume a permission you revoked a moment ago has already stopped working everywhere. If you are new to AWS overall, our AWS tutorial for beginners covers accounts, Regions and your first resources, and the official starting point is AWS’s own Getting started with IAM guide, which sets out the same concepts from the service’s own documentation.

The Root User: Lock It Down First

The root user is the identity created when you opened your AWS account. It is the email address and password you signed up with, and it has unrestricted access to everything in the account, including billing, account closure and the ability to delete every resource you own. It is also the most attacked identity in your account, because its username — your email address — is often public knowledge.

Your first job in any AWS account is to make the root user hard to use and almost never used. Enable multi-factor authentication on it immediately, using a hardware key or an authenticator app rather than SMS where possible. Store the root credentials in a password manager, not in a document or an email thread. Never create access keys for the root user — there is no normal task that needs programmatic root access — and never use the root user for daily work. Create an administrative IAM user or, better, set up AWS IAM Identity Center and use that for everyday administration, so the root user stays locked away for the handful of tasks that genuinely require it, such as changing the account email or closing the account.

Check your own account now. Sign in to the console, open IAM, and look at the Security Status dashboard: it tells you whether root MFA is on, whether there are access keys older than best practice, and whether a password policy exists. Fix every warning on that page before you create your first workload. AWS also publishes a credential report — a downloadable file listing every user, their MFA status, their access keys and the last time each credential was used — which is the fastest way to find stale credentials across an account with many users.

aws iam get-credential-report
aws iam generate-credential-report
aws iam get-account-summary

The account summary is worth reading in full. It shows the number of users, groups, roles and policies in the account, whether MFA is enabled for the root user, and whether a password policy is configured. Run it after every change in this tutorial and watch the numbers move — it is the quickest feedback loop IAM offers.

IAM Users and Groups

An IAM user represents a person or an application that needs to interact with AWS. Each user has a name, an Amazon Resource Name (ARN) that uniquely identifies it, and credentials: a console password for signing in to the web console, access keys for programmatic access, or both. A user belongs to exactly one AWS account, and by default it can do nothing at all until you attach policies to it directly or through a group.

Create users through groups, not one at a time with individual policies. A group is a collection of users that share permissions: attach a policy to the group once, add users to it, and every member inherits those permissions. When someone changes team, you move them between groups instead of rewriting their permissions, and when someone leaves, you remove them from the group or deactivate the user. That is the difference between an IAM setup that survives a year of team changes and one that collapses into a pile of individual policies nobody dares to touch.

aws iam create-group --group-name developers

aws iam create-user --user-name priya

aws iam add-user-to-group --group-name developers --user-name priya

aws iam attach-group-policy --group-name developers \
  --policy-arn arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess

aws iam create-login-profile --user-name priya \
  --password 'Use-A-Strong-Temporary-Password-1' --password-reset-required

That sequence creates a group, a user, adds the user to the group, attaches AWS’s managed read-only EC2 policy to the group, and gives the user a console password that must be changed at first sign-in. Managed policies are AWS’s pre-written policies for common jobs — read-only access, power user access, administrator access — and they are the right starting point while you learn, because they are maintained by AWS and cover the obvious cases. The IAM users page in the official user guide explains the same model: a user consists of a name and credentials, has no permissions by default, and gets them from policies attached directly or through groups.

A word on modern practice. AWS’s current best practice is to require human users to use federation with an identity provider — such as your company’s identity system or AWS IAM Identity Center — and temporary credentials, instead of IAM users with long-term credentials. For a small team or a personal account, IAM users are still the way most people start, and they are what this tutorial teaches, because the concepts transfer directly. But know the direction of travel: if you join a company with a mature AWS setup, expect to sign in through Identity Center and never see a long-term access key at all.

IAM Policies: The JSON That Grants Access

A policy is a JSON document that answers three questions: who can do what, to which resource, and under which conditions. The core elements are Effect (Allow or Deny), Action (the API operations, such as s3:GetObject), Resource (the ARN of the thing being acted on) and Condition (optional rules, such as the time of day or the source IP). A policy with no matching Allow is a denial, and an explicit Deny beats any Allow, which is how you build guardrails that even an administrator policy cannot override.

Here is a policy that lets a user list and read objects in one specific S3 bucket and nothing else. Read it slowly, because this shape — one effect, a small list of actions, a single resource — is the template for almost every good policy you will ever write:

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

Notice the two resource ARNs. S3 distinguishes the bucket itself (arn:aws:s3:::acme-app-assets) from the objects inside it (arn:aws:s3:::acme-app-assets/*), and ListBucket applies to the bucket while GetObject applies to the objects. Forgetting one of the two is the most common reason a policy that looks right still returns AccessDenied, and it is the first thing to check when a read fails. The Version field is always 2012-10-17 — it is the policy language version, not a date you update.

There are two kinds of policy to know. Identity-based policies attach to users, groups or roles and say what that identity can do. Resource-based policies attach to the resource itself — an S3 bucket policy, for example — and say who can access it, including identities from other accounts. Most day-to-day access uses identity-based policies; resource-based policies are how you grant cross-account access or make a bucket public, and they deserve extra review because a mistake there can expose data to the whole internet.

Test a policy before you trust it. The IAM policy simulator lets you select a user, a policy and an action, and shows whether the request would be allowed or denied and which statement decided it. Use it whenever a policy behaves unexpectedly, and use Access Analyzer to check for policies that grant access to external accounts. A policy that is too broad usually announces itself in the simulator long before it causes an incident.

IAM Roles and Temporary Credentials

A role is an identity with permissions but no permanent credentials. Instead of a password or an access key, a role is assumed: a trusted entity asks AWS Security Token Service for temporary credentials, uses them for a limited time, and then they expire. Roles are how AWS services get permissions — an EC2 instance with a role can read from S3 without any access key stored on the instance — and how people get short-lived elevated access without a standing administrator account.

The classic example is an EC2 instance that needs to read files from S3. The wrong approach is to create an IAM user, generate access keys, and copy them onto the instance, where they can be stolen from disk, from a backup, or from a log file. The right approach is a role with a trust policy that allows the EC2 service to assume it, and a permissions policy that allows only the S3 reads the application needs:

aws iam create-role --role-name app-server-s3-read \
  --assume-role-policy-document '{
    "Version": "2012-10-17",
    "Statement": [{
      "Effect": "Allow",
      "Principal": {"Service": "ec2.amazonaws.com"},
      "Action": "sts:AssumeRole"
    }]
  }'

aws iam attach-role-policy --role-name app-server-s3-read \
  --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess

aws iam create-instance-profile --instance-profile-name app-server-profile
aws iam add-role-to-instance-profile \
  --instance-profile-name app-server-profile --role-name app-server-s3-read

The trust policy is the part beginners overlook. It is a separate document from the permissions policy, and it answers a different question: who is allowed to assume this role at all. A role with generous permissions and a sloppy trust policy — one that allows any AWS account to assume it — is worse than no role, because it hands those permissions to anyone who finds the role ARN. Keep trust policies narrow: the specific service, the specific account, or the specific federated identity that needs it, and use external IDs for cross-account roles so that a confused-deputy attack cannot assume the role from an unexpected caller.

Roles are also the mechanism behind the two patterns you will meet most in production. The first is cross-account access: an auditor in one account assumes a read-only role in another, with no shared credentials. The second is deployment: a CI pipeline assumes a role with exactly the permissions the deployment needs, for the duration of the job, instead of storing a long-lived access key in the pipeline’s secrets. Lambda functions take the same approach — each function runs with an execution role, and the function’s permissions are the role’s permissions. Our AWS Lambda serverless tutorial shows an execution role in a working function, including the CloudWatch Logs permissions every Lambda role needs and beginners always forget.

MFA, Access Keys and Credential Hygiene

Multi-factor authentication is the cheapest security improvement in all of AWS. It adds a second factor — a code from an authenticator app or a hardware key — to a password sign-in, so a stolen password alone is not enough to enter the account. Enable MFA for the root user first, then for every human user with console access, and require it for sensitive actions by adding a condition to your policies that denies the action unless MFA is present. That condition is what turns “please use MFA” into “you cannot do this without MFA”, and it is the difference between a policy and a hope.

Access keys deserve the same discipline. Each user can have at most two access keys, and you should treat that as a ceiling, not a target: one active key per user is the norm, and the second exists only briefly during rotation. Rotate keys regularly — a common cadence is every 90 days — by creating the new key, updating every place that uses it, and then deactivating the old one before deleting it. The gap between deactivation and deletion is your safety net: if something still uses the old key, you will see failures you can fix by reactivating it, instead of an outage you cannot undo. The CLI commands for rotation are short, and they are worth scripting rather than doing by hand, because a manual rotation is a rotation that gets skipped:

aws iam create-access-key --user-name priya
aws iam list-access-keys --user-name priya
aws iam update-access-key --user-name priya --access-key-id AKIAIOSFODNN7EXAMPLE --status Inactive
aws iam delete-access-key --user-name priya --access-key-id AKIAIOSFODNN7EXAMPLE

Enforcing MFA through policy is the step that turns a good intention into a guarantee. This policy denies every action unless the request was authenticated with MFA, and it still allows the user to manage their own MFA device so they can enrol without an administrator’s help:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Deny",
      "Action": "*",
      "Resource": "*",
      "Condition": {
        "BoolIfExists": {
          "aws:MultiFactorAuthPresent": "false"
        }
      }
    }
  ]
}

Attach that policy with care: applied to the wrong group it locks everyone out, including the person trying to fix it, so test it on a single user first and keep a break-glass administrator path that is itself protected by MFA and stored offline. The condition key aws:MultiFactorAuthPresent is the mechanism, and BoolIfExists handles the case where the key is absent entirely, which is exactly what happens for a request made without MFA.

Never put access keys where they can leak. Do not commit them to a repository, do not paste them into a chat message or a ticket, and do not store them in an application configuration file that ships with the code. Use environment variables or a secrets manager for local development, and roles for anything running on AWS. If a key is ever exposed — in a public repository, a screenshot, a log file — treat it as compromised: deactivate it immediately, look at CloudTrail for what it was used for, and only then create a replacement. AWS’s own guidance is blunt on this point, and it is right: a leaked key is an incident, not a tidy-up task.

Set a password policy for console users: a minimum length, required character types, and a rule that passwords expire or cannot be reused. Enforce it in IAM rather than asking people to follow it voluntarily, because a policy is enforced and a request is not. And review the credential report on a schedule — monthly is a good cadence — to find keys that have not been used in months, users with no MFA, and accounts that should have been deactivated when someone left. Stale credentials are the credentials attackers find.

Least Privilege in Practice

Least privilege means giving every identity only the permissions it actually needs, and nothing more. It sounds simple and it is genuinely hard, because the easy alternative — AdministratorAccess for everyone — works immediately and fails silently. The discipline is to start narrow, watch what breaks, and widen deliberately, rather than starting wide and promising to tighten later, which nobody ever does.

Build the habit with a repeatable loop. Start from a managed read-only policy for a new team member, add the specific write actions their job needs, and use IAM Access Analyzer’s policy generation to turn a period of real activity into a draft policy based on what the identity actually used. That generated policy is a far better starting point than a guess, because it reflects the real API calls instead of your mental model of them. Review it before you attach it — generated policies can include actions that were used once by accident — and repeat the loop every few months as the workload changes.

Permission boundaries and service control policies are the guardrails for larger accounts. A permission boundary caps what a role or user can do, no matter what other policies allow, so a developer can be given broad permissions inside a boundary that prevents them from touching billing or IAM itself. A service control policy, applied through AWS Organizations, caps what an entire account can do. Both are advanced tools, but they solve the problem that least privilege alone cannot: an identity that is correct today and dangerous after an innocent-looking policy edit tomorrow.

When access is denied, debug it methodically instead of adding AdministratorAccess and moving on. First, find the exact action and resource in the error message or in CloudTrail. Second, check which policies apply to the identity — direct policies, group policies, the role’s policies, permission boundaries and service control policies — and look for an explicit Deny, which beats any Allow. Third, use the policy simulator to test the exact request. Fourth, check conditions: an MFA condition, a source-IP condition or a time condition can deny a request that looks allowed. Kubernetes workloads hit this constantly, because an EKS cluster’s node roles and pod identities are IAM roles, and a missing permission surfaces as a pod that cannot pull an image or write a log. Our AWS EKS tutorial covers the IAM roles an EKS cluster needs and the errors you see when one is missing.

Frequently Asked Questions

What is the difference between an IAM user and an IAM role?

A user has permanent credentials — a password, access keys, or both — and represents a person or an application. A role has no permanent credentials; it is assumed for temporary credentials by a trusted service, user or account. Use users for people and roles for services, applications and temporary access.

Why does my new IAM user get AccessDenied for everything?

Because a new user has no permissions by default. Until a policy is attached to the user directly or through a group, every request is denied. Attach a policy — a managed read-only policy is a good first step — and test again.

Should I ever create access keys for the root user?

No. There is no normal task that needs programmatic root access, and a root access key is the most damaging credential that can leak. Use the root user only for the few console tasks that require it, protect it with MFA, and give programmatic access to IAM users or roles instead.

What is the difference between an identity-based policy and a resource-based policy?

An identity-based policy attaches to a user, group or role and says what that identity can do. A resource-based policy attaches to a resource, such as an S3 bucket, and says who can access it, including identities from other accounts. Most access uses identity-based policies; cross-account access often needs a resource-based policy too.

How do I know which permissions a role actually needs?

Start from what the workload really calls, not from a guess. Use CloudTrail to see the API calls an identity makes, and IAM Access Analyzer’s policy generation to turn that activity into a draft least-privilege policy. Then review it, remove anything that was used once by accident, and attach it.

Conclusion

IAM is not a formality you complete before the real work — it is the real work, because every AWS workload runs on the permissions you grant. Lock down the root user, organise people into groups, write policies that name exactly what is allowed, and give services roles instead of keys. Check the credential report monthly, rotate keys on a schedule, and treat a leaked credential as an incident. Do those things and your account will survive the mistakes that every team makes; skip them and the first leaked key or over-broad policy will decide your security posture for you. Your next step is practical: open your own account, enable root MFA if it is not already on, and build one user, one group and one scoped policy exactly as this tutorial describes.

Scroll to Top