IAM user vs IAM role: long-term or temporary credentials?
An IAM user identifies a specific person or workload, can have a long-term password or access keys, and can also obtain temporary credentials through AWS STS; an IAM role has no long-term credentials of its own and is assumed to obtain temporary credentials. AWS recommends preferring temporary credentials wherever possible.
Compare by characteristic
| Characteristic | IAM user | IAM role |
|---|---|---|
| Credentials | Long-term password or access keys | Temporary, issued through AWS STS when the role is assumed |
| Who uses it | One specific person or application | Any trusted identity: EC2, Lambda, another account or a federated user |
| Risk if keys leak | Long-term keys can be abused until revoked | Credentials expire, limiting the blast radius |
When to use which
Applications running on EC2 or Lambda should use a role instead of storing access keys on the machine. Cross-account access and federation also use roles. A role has two main parts: a trust policy defining who may assume it and a permission policy defining what it may do.
- Attach a role to EC2 through an instance profile.
- Apply least privilege to users and roles alike.
Check your understanding
When a scenario asks how an application on EC2 can get permissions without storing access keys, the answer is an IAM role through an instance profile. Do not write keys into User Data or source code.
References
Use AWS documentation to check current features and limits. Cloud Quest is an independent learning project and does not guarantee exam outcomes.