AWS in 1 Min · Episode 19

IAM users vs roles: what's the difference?

Permanent keys or temporary hats. Watch the one-minute video, then read the details.

David Gomez1:16 video · 3 min read

"Every app needs its own IAM user." That used to be how people did it, and it's the source of a lot of leaked credentials. An IAM user comes with long-term access keys that never expire on their own. Copy them into a config file, a laptop or a repository, and they keep working for whoever finds them. For almost every case today, the right answer is an IAM role.

IAM users: long-term credentials

An IAM user is a single identity inside your account with its own long-term credentials:

  • a password to sign in to the console
  • access keys (an access key ID and a secret) for the CLI, SDKs and scripts

Those credentials stay valid until someone changes or deletes them. That's the problem: keys get pasted into code, shared in chat, left on old servers. Rotating them is manual work that tends to be postponed.

IAM roles: temporary hats

A role is also an identity with permissions, but it has no password and no access keys. Think of it as a hat. Anyone you trust can put it on, and while they wear it they have the role's permissions.

When someone or something assumes a role, AWS Security Token Service (STS) issues temporary credentials. By default a session lasts one hour; a role can be configured to allow longer sessions, up to twelve hours. When the time is up the credentials stop working, so a leaked set has a short life.

On AWS compute you rarely see any of this. Attach a role to an EC2 instance or a Lambda function and the AWS SDK picks up the temporary credentials and refreshes them automatically. There is nothing to store.

The trust policy: who may wear the hat

Every role has two parts:

  • a permissions policy: what the role can do
  • a trust policy: who is allowed to assume it

The trust policy can name an AWS service (a server, a function), another AWS account, or an identity provider such as your company's single sign-on. That's how cross-account access works without sharing keys: account B creates a role that trusts account A.

So when do you still need an IAM user?

Rarely. AWS recommends:

  • People sign in through IAM Identity Center (or another identity provider) and receive a role with temporary credentials.
  • Workloads on AWS use roles attached to the compute service.
  • Workloads outside AWS can get temporary credentials too, for example with IAM Roles Anywhere or OpenID Connect federation from a CI/CD platform.

IAM users remain for the few tools that can't work any other way, such as some third-party clients that only accept access keys. If you must use one, give it minimal permissions, rotate the keys, and remove it when it's no longer needed.

A common mistake is creating one IAM user "for the app", giving it broad permissions, and reusing its keys in every environment. One leak then exposes everything.

Where AI fits

AI agents and AI applications are workloads, so the same rule applies. An agent running on AWS, for example in Amazon Bedrock AgentCore Runtime, on Lambda or in a container, gets its permissions from an execution role, with temporary credentials. Never paste a user's access keys into an agent's configuration, its prompt or its tools: prompts and logs get stored and shared, and long-lived keys in them are a leak waiting to happen. Give each agent its own narrowly scoped role instead.

Quick recap

  • IAM users hold long-term passwords and access keys that never expire on their own.
  • IAM roles have no keys; assuming one gives temporary credentials, one hour by default.
  • Apps, agents and people should all use roles. Keep users for rare exceptions.
AWS in 1 Min #19 · 1:16

Need an AWS expert on your team?

I'm David, an AWS expert and fractional cloud consultant. I work alongside your team to run your cloud and infrastructure: architecture, security, cost and day-to-day operations. You get senior AWS experience when you need it, without the cost of a full-time hire.

  • Architecture reviews and a clear plan for what to fix first
  • Security hardening: IAM, networking, audits
  • Lower AWS bills without slowing your team down
  • Hands-on help with AI workloads on AWS