Skip to content
VirtualLP Virtual Learning Platform

IAM in Depth: Users, Groups, Roles, Policies and Policy Evaluation

15 min read Topic 3 of 30 1 hands-on lab

IAM decides who can do what on which resources in your AWS account. Every API call – from the console, the CLI, an SDK or a Lambda function – is authenticated and then authorised by IAM.

Identities

Identity Credentials Use for
Root user E-mail + password Only account-level tasks; enable MFA and lock away
IAM user Password and/or long-term access keys A person or a legacy app (prefer Identity Center for people)
IAM group – (a collection of users) Attach policies once for a job function (Developers, Admins)
IAM role Temporary credentials from STS Services (EC2, Lambda, ECS), cross-account access, federated users
Key point

Roles beat access keys. A Lambda function or EC2 instance should assume a role; its credentials rotate automatically and are never stored in code.

Policies – the JSON language

{
  "Version": "2012-10-17",
  "Statement": [{
    "Sid": "ReadOrdersTable",
    "Effect": "Allow",
    "Action": ["dynamodb:GetItem", "dynamodb:Query"],
    "Resource": "arn:aws:dynamodb:ap-south-1:123456789012:table/Orders",
    "Condition": { "Bool": { "aws:SecureTransport": "true" } }
  }]
}
Element Meaning
Effect Allow or Deny
Action API operations, service:Operation, wildcards allowed (s3:Get*)
Resource ARNs the statement applies to
Condition Optional – IP, MFA, tags, time, encryption…
Principal Only in resource-based policies – who is allowed

Types of policy

Type Attached to Example
AWS managed Identities AmazonS3ReadOnlyAccess
Customer managed Identities Your reusable least-privilege policy
Inline One identity only A role-specific exception
Resource-based A resource S3 bucket policy, Lambda resource policy, KMS key policy
Trust policy A role Who may assume the role (lambda.amazonaws.com)
Permissions boundary / SCP Identity / account Maximum permissions guard-rails

How AWS evaluates a request

flowchart TD
    A[Request: principal + action + resource] --> B{Any explicit Deny?}
    B -- yes --> D[DENY]
    B -- no --> C{Any Allow in identity or resource policy?}
    C -- yes --> E["ALLOW (within boundaries / SCPs)"]
    C -- no --> F[DENY – implicit]
  1. Everything starts denied (implicit deny).
  2. An explicit Deny anywhere always wins.
  3. Otherwise an Allow grants access – if no boundary or SCP blocks it.

An error such as User: arn:aws:sts::…:assumed-role/my-fn-role/… is not authorized to perform: dynamodb:PutItem on resource: …table/Products tells you exactly which action and resource to allow.

Least privilege in practice

  • Start from the actions your code actually calls; scope Resource to specific ARNs.
  • Prefer groups for people and roles for workloads.
  • Use IAM Access Analyzer and last accessed data to remove unused permissions.
  • Require MFA for humans; rotate or eliminate access keys.

Temporary credentials – STS

The Security Token Service issues short-lived credentials when a role is assumed (AssumeRole), when a federated user signs in (SSO), or when a service such as Lambda starts. aws sts get-caller-identity shows who you currently are.

Practise it

Virtual lab · Amazon Web Services · 30 min

Implement a least-privilege security policy with AWS IAM

Turn a written security policy into IAM controls: groups by job function, users without admin rights, a custom JSON policy scoped to one bucket and programmatic access keys.

Open lab

Quick revision

  1. Users/groups for people, roles for services; avoid long-term keys.
  2. Policy = Effect + Action + Resource (+ Condition).
  3. Explicit deny > allow > implicit deny.
  4. Resource policies include a Principal; trust policies decide who assumes a role.
  5. Grant only what is needed, on specific ARNs.

Practise this topic

Hands-on virtual lab

Apply what you just read in a realistic, guided simulation. Free with a verified account.

Create a free account to track your progress and unlock virtual labs.