IAM

6 min read

Reading Progress0%
AWS Essentials Index
Tier 1 -- Mental Model
Tier 2 -- Core Services
Compute
Storage
Databases
API & Traffic
Messaging & Events
Observability
Tier 3 -- Architecture Patterns
AWS Essentials Index
Tier 1 -- Mental Model
Tier 2 -- Core Services
Compute
Storage
Databases
API & Traffic
Messaging & Events
Observability
Tier 3 -- Architecture Patterns

IAM

1. What Is It?

AWS Identity and Access Management () is the system that controls who (or what) can do what in your AWS account. It defines identities (users, groups, roles) and attaches policies — JSON documents that grant or deny specific API actions on specific resources.

Without , every person and every service would have unlimited access to every resource in your account. A compromised developer machine would mean full access to production databases. A bug in a function could accidentally delete buckets. IAM is the mechanism that enforces least-privilege access across everything in AWS — it is consulted on every single API call.


2. How It Works

The core model

Every AWS API call goes through a 4-step authorization check:

Default is deny. If no policy explicitly allows an action, it is denied. An explicit Deny always overrides any Allow.

Identities

IdentityWhat it isCommon use
IAM UserA person or system with long-term credentials (access key + secret)Human accounts, CI/CD pipelines (legacy)
IAM GroupA named collection of usersAssign policies to teams: Developers, Ops
IAM RoleA temporary identity assumed by a service, user, or external entityEC2 instances, Lambda functions, cross-account access

Roles are how services authenticate. A function doesn't log in with a username and password — it runs under a role. When it calls or , checks the permissions attached to that role.

Policies

A policy is a JSON document listing what actions are allowed or denied:

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

Policy types:

  • AWS Managed Policies — pre-built by AWS (e.g., AmazonS3ReadOnlyAccess). Convenient but often broader than needed.
  • Customer Managed Policies — you write and maintain them. Recommended for production.
  • Inline Policies — embedded directly on a user/role. Avoid — hard to audit and reuse.
  • Resource-based Policies — attached to a resource ( bucket policy, queue policy) rather than an identity. Used for cross-account access.

Assuming a Role

Roles are not credentials you use directly — you assume them. Assuming a role calls AWS STS (Security Token Service), which returns temporary credentials (access key, secret, session token) that expire in 15 minutes to 12 hours.

AWS SDKs do this automatically. You rarely call STS directly in application code.


QUICK CHECK

Your team is deploying a Lambda function that needs to read objects from an S3 bucket. A junior engineer suggests creating an IAM User with an access key and hardcoding those credentials in the Lambda's environment variables. What is the recommended approach instead, and why?

Choose one answer

3. What Backend Engineers Actually Need to Know

Use roles for everything that isn't a human. instances, functions, ECS tasks, CodeBuild jobs — all of them should run under an role. Never embed access keys in application code or environment variables if you can avoid it.

The ARN (Amazon Resource Name) is how you identify resources in policies. Format: arn:aws:<service>:<region>:<account-id>:<resource-type>/<resource-id>. In policy Resource fields, * is a wildcard: arn:aws::::my-bucket/* means all objects in the bucket.

Common misunderstandings:

  • "I'll just give my AdministratorAccess to make it work." — This works, but it means a single compromised function or bug can delete any resource in your account. Always scope to the minimum required.
  • " is only for humans." — Most IAM complexity in production systems involves service-to-service authentication, not human users.
  • "Permissions are additive." — Mostly true, but explicit Deny always wins. A Deny anywhere in the evaluation chain blocks the action, even if another policy allows it. Service Control Policies (SCPs) in AWS Organizations can also deny actions at the organization level.
  • "Cross-account access requires creating IAM users in each account." — No. Use cross-account role assumption: the Lambda in Account A assumes a role in Account B. The role in Account B has a trust policy allowing Account A to assume it.

QUICK CHECK

Your Lambda function needs read access to a specific S3 bucket. A teammate suggests attaching AdministratorAccess to the Lambda's IAM role so you don't have to figure out the exact permissions needed right now. What is the primary security risk of this approach?

Choose one answer

4. Tradeoffs & Decisions

User vs. Role:

  • IAM Users have long-term credentials. If the access key leaks, it's valid until rotated. Roles use temporary credentials that expire automatically — far safer.
  • Use IAM Users only for: human console access (when SSO/Identity Center isn't set up) and legacy CI/CD systems that can't assume roles.
  • Prefer AWS IAM Identity Center (formerly SSO) for human access and role assumption for everything else.

Broad managed policies vs. narrow custom policies:

  • AdministratorAccess and PowerUserAccess are convenience policies that have no place in production workloads. They exist for bootstrapping and dev accounts.
  • Writing narrow policies takes time but shrinks your blast radius when credentials are compromised.
  • "If you see X, it usually means Y": if a developer says "I just gave it full access," it likely means the policy allows :* on * — meaning it can delete any bucket in the account. Scope by action and by Resource ARN.

Trust policies:

  • A role has two parts: the permissions policy (what the role can do) and the trust policy (who can assume the role). A role with AmazonS3FullAccess but a trust policy that only allows .amazonaws.com can only be assumed by — not , not a human.

QUICK CHECK

A Lambda function needs read access to an S3 bucket. A developer creates an IAM role with an AmazonS3ReadOnlyAccess permissions policy and a trust policy that only lists ec2.amazonaws.com as a trusted principal. What happens when Lambda tries to assume this role?

Choose one answer

5. Interview Cheat Sheet

Key sentences:

  1. " is consulted on every AWS API call — the default is deny, and a single explicit Deny overrides any number of Allow statements."
  2. "Services authenticate using Roles, not long-term credentials — the metadata service or runtime automatically fetches temporary credentials from STS."
  3. "Least privilege isn't just a best practice — it's the difference between a misconfigured deleting one table vs. every table in the account."
  4. "Resource-based policies (like bucket policies) enable cross-account access without creating IAM users in every account."

Common follow-ups:

Q: How does a Lambda function get permissions to write to ? A: You attach an execution role to the Lambda with a policy that allows :PutItem (and other needed actions) on the specific table ARN. The Lambda runtime fetches temporary credentials for that role from the metadata service equivalent, and the AWS SDK uses them automatically.

Q: What's the difference between an identity-based policy and a resource-based policy? A: Identity-based policies are attached to a principal (user, role, group) and say what that principal can do. Resource-based policies are attached to a resource ( bucket, queue) and say who can access that resource. Both must allow the action for cross-account access to work.

Q: Why should you avoid long-term IAM access keys? A: Long-term keys don't expire. If they're leaked in a git commit, log file, or environment variable, an attacker has permanent access until you manually rotate or delete the key. Roles produce temporary credentials that expire automatically (15 min to 12 hours), limiting the window of exposure.

Glossary History

Click dotted jargon to save explanations here.

Glossary History

Click dotted jargon to save explanations here.