AWS Builder Center
 IAM Roles vs IAM Users: Which One Should Your App Use?

IAM Roles vs IAM Users: Which One Should Your App Use?

Long-lived access keys are one of the easiest ways to leak an AWS account. Here's the difference between IAM users and roles, and a 4-step checklist to make your setup safer today.

Engineering Student | Cloud DevOps & SRE Engineer
If your app talks to AWS, it needs an identity. The first choice is IAM user or IAM role, and the wrong one is how most keys end up leaked.
IAM user: a permanent identity with a password and/or access keys. Those keys don't expire. If they land in a GitHub repo, a log file or a screenshot, anyone can use them until you notice and delete them.
IAM role: an identity that anything trusted can assume for a short time. AWS hands out temporary credentials that expire automatically, usually within hours. Nothing permanent exists to leak.
So which should an app use?
  • App on EC2: attach an instance profile (a role). The SDK picks up credentials by itself. No keys in code.
  • Lambda: give the function an execution role.
  • GitHub Actions or other CI: use OIDC to assume a role, not stored access keys.
  • A human logging in: use IAM Identity Center or a user with MFA, and avoid long-lived keys.
Least privilege matters just as much. A role that can do everything is only a safer-looking admin. Give it just the actions and resources it needs, for example s3:GetObject on one bucket, not s3:*.
4-step checklist:
  1. Search your code and repos for AKIA (the prefix of access key IDs). Remove what you find.
  1. Replace app keys with roles wherever you can.
  1. Enable MFA on every human user, and delete unused users.
  1. Rotate or delete any access key older than 90 days.
Takeaway: if a credential can be copied and used from anywhere, treat it as a liability. Prefer credentials that expire on their own.
What's one place in your setup where you still use long-lived keys?
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article