Choosing IAM Users, Groups and Roles
This lesson explains each kind of IAM identity, which credentials it uses and when it is the right choice, since every request on AWS is made by an IAM principal.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish the root user, IAM users, groups and roles.
- Explain how trust policies and permissions policies define a role.
- Protect the root user and remaining IAM users.
- Replace long-term access keys with roles.
Identities
IAM provides several types of identity, which differ in the credentials they use. The root user is created with the account and has full access that no IAM policy can restrict. It should be used only for the few tasks that require it, such as changing the account's support plan, and protected with MFA and no access keys.
An IAM user has long-term credentials: a console password, access keys, or both. Because long-term keys can leak and do not expire, IAM users are rarely the right answer today; employees sign in through IAM Identity Center instead. An IAM group is a collection of users that share permissions. A group has no credentials of its own, cannot contain other groups, and cannot be named as a principal in a policy.
An IAM role has no permanent credentials. A trusted principal, such as an AWS service, a user in another account or a federated user, assumes the role and receives temporary credentials that expire automatically. Roles are how EC2 instances, Lambda functions and ECS tasks call AWS services, through instance profiles, execution roles and task roles. A service-linked role is a role that a service creates and manages for itself, such as the role Auto Scaling uses to launch instances; its permissions can be viewed but not changed. The following table summarises the identity types.
| Identity | Credentials | Use for |
|---|---|---|
| Root user | Full, unrestrictable access | Only the tasks that require it; protect with MFA, no access keys |
| IAM user | Long-term password and/or access keys | Rarely needed today; workforce users belong in IAM Identity Center |
| IAM group | None; attaches permissions to its users | Managing many users; groups cannot be nested and cannot be a principal |
| IAM role | Temporary, when a trusted principal assumes it | AWS services (instance profiles, Lambda execution roles, ECS task roles), other accounts, federated users |
| Service-linked role | Managed by a service | Services such as Auto Scaling or ELB; you can view but not change its permissions |
A role for the workload is always better than shared keys, whether the caller is an instance, a container or a function.
Which identity?
How roles work
An IAM role is an identity without long-term credentials. It is defined by two kinds of policy. Its trust policy states who may assume it, such as an AWS service, another account or a federated user. Its permissions policies state what it may do once assumed.
Assuming a role returns temporary credentials from AWS Security Token Service (AWS STS) that expire automatically, so there is nothing long-lived that can leak. Workloads receive roles in different ways: an EC2 instance receives a role through an instance profile, while Lambda functions, ECS tasks and other services assume their roles themselves. To give a role to a service, for example when creating a Lambda function, a user needs the iam:PassRole permission for that role, which prevents users from escalating their privileges by handing a more powerful role to a service.
The following diagram shows how a workload obtains and uses a role's credentials.

How roles work
Protecting the root user and remaining IAM users
The root user and any remaining IAM users hold long-term credentials, so they need particular protection. The root user can do anything in the account and cannot be restricted by IAM policies. It should have MFA enabled, have no access keys, and be used only for the few tasks that require it. In AWS Organizations, centralised root access management can remove member accounts' root credentials altogether.
Remaining IAM users should have a password policy and MFA, and their access keys should be rotated or, better, removed in favour of roles. The credential report lists every user's password and access key ages, which shows stale credentials, and last accessed information shows which services each identity actually uses, which identifies permissions that can be removed.
Removing long-term keys from an application
An application on EC2 reads from S3 using an IAM user's access keys stored in a configuration file. An audit flags the keys as a risk: they never expire and would work from anywhere if leaked.
| Step | Action |
|---|---|
| 1 | Create a role trusted by ec2.amazonaws.com with a policy allowing s3:GetObject on the one bucket |
| 2 | Attach the role to the instances through an instance profile |
| 3 | Remove the keys from the configuration file; the SDK now uses the role's temporary credentials automatically |
| 4 | Deactivate, then delete, the IAM user's keys |
The application code does not change, because the SDK's credential chain finds the instance role. Credentials now rotate automatically every few hours and exist only on the instance. The same principle applies to every compute service: Lambda execution roles, ECS task roles, EKS Pod Identity.
What should be done with the root user's access keys?
Show answer
Delete them, or never create them, enable MFA on the root user and use it only for the few tasks that require it.
Exam Tips
Remember for the exam
- Applications on EC2, Lambda and ECS should use roles; never store access keys on instances or in code.
- Manage permissions for many users through groups.
- A group cannot be a principal in a policy and cannot contain other groups.
- To find unused access keys and old passwords, use the IAM credential report.
- Protect the root user with MFA and give it no access keys.