
AWS IAM Explained: Users, Groups, Roles, and Policies
Learn how IAM identities and JSON policies work together, then see how to give an EC2 workload read-only access to one S3 reports path using temporary credentials.
AWS IAM Explained: Users, Groups, Roles, and Policies—with Practical Examples
Summary: Learn how IAM identities and JSON policies work together, then see how to give an EC2 workload read-only access to one S3 reports path using temporary credentials.
Why IAM is more than a list of users
When I first learned AWS, I thought of IAM mainly as the place where users and passwords lived. A more useful way to think about it is as the account’s authorization system: it evaluates who is making a request, what action they want to perform, which resource they target, and any conditions on the request.
A request is allowed only when an applicable policy allows it and no applicable explicit deny blocks it. That makes the policy’s
Action , Resource , and optional Condition just as important as its Effect .Four IAM building blocks
- Users are IAM identities for a person or workload that needs long-term credentials. For human access, AWS recommends federation and temporary credentials where possible; avoid creating long-lived access keys for routine use.
- Groups collect IAM users so a shared set of identity-based permissions can be managed in one place. Groups cannot contain roles or other groups.
- Roles are identities with permissions and a trust policy that says which principals may assume them. A role provides temporary credentials when assumed.
- Policies are JSON permission documents. Identity-based policies attach to users, groups, or roles. Resource-based policies attach to supported resources, such as an S3 bucket, and name principals that may access them.
A role’s trust policy answers who may assume the role. Its permissions policies answer what the role may do after it is assumed. These are separate checks.
Least privilege: read only the reports path
Suppose an application needs to read objects under
reports/ in a bucket named company-app-reports . This identity policy grants GetObject only for objects in that path. It also allows listing only that prefix, which some applications need to discover object keys.{ "Version": "2012-10-17", "Statement": [ { "Sid": "ReadReportsObjects", "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::company-app-reports/reports/*" }, { "Sid": "ListOnlyReportsPrefix", "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::company-app-reports", "Condition": { "StringLike": { "s3:prefix": [ "reports/", "reports/*" ] } } } ]}Replace the example bucket name with the real bucket name. If the application already knows each object key and never lists keys, remove the
ListBucket statement. If it should read only a narrower folder, change both the object ARN and allowed prefix. This example is for programmatic S3 access; the S3 console may need additional permissions to display navigation and account information.The policy deliberately does not include
PutObject , DeleteObject , or s3:* . Those actions are unnecessary for a reader. In a real account, permissions are also affected by other applicable controls, such as resource policies, permissions boundaries, session policies, and AWS Organizations service control policies. Review the complete access path and test the policy before relying on it.What happens when an EC2 application reads from S3?
Here is the flow I use to reason about workload access:
- Create an IAM role for the application. Its trust policy allows the EC2 service principal (
ec2.amazonaws.com) to assume it.
- Attach the least-privilege S3 permissions policy above to the role.
- Associate the role with the EC2 instance through an instance profile. The console manages this association for you; when using APIs or infrastructure tools, the role and instance profile may be separate resources.
- The application’s AWS SDK uses its standard credential provider chain to obtain temporary role credentials made available through the EC2 instance metadata service. The SDK refreshes credentials as needed.
- The application calls S3 using those credentials. IAM evaluates the role’s permissions alongside any other applicable policies.
The application does not need a long-term access key in a config file or source code. Protect access to instance metadata, and use IMDSv2 where appropriate. Also remember that one EC2 instance role is shared by applications on that instance; separate workloads onto separate tasks or compute boundaries when they need different permissions.
A practical way to review a policy
Before attaching a policy, I ask:
- Which exact API actions does the workload call?
- Which exact resources do those actions target? (Bucket-level and object-level actions often use different ARN forms.)
- Can I narrow the resource further by prefix, account, region, or request condition?
- Does the role trust only the service or principal that needs it?
- Can I test the intended and unintended cases with IAM Access Analyzer or a controlled test account?
IAM Access Analyzer can help validate policies and identify overly broad access, but a tool result does not replace understanding the application’s required actions.
Takeaway
Users and groups help organize identities and shared permissions. Roles let trusted people, AWS services, and workloads receive temporary credentials. Policies define allowed actions on resources under specific conditions. The habit that ties the pieces together is to start with the one task the identity must perform, scope the policy to that task, and review how all applicable policies combine.
I’m learning to read IAM policies by tracing a real request from principal to action to resource. The EC2-to-S3 example makes that process concrete: trust lets EC2 provide the role credentials, while the role’s permissions policy limits which S3 operations those credentials can perform.
References
Suggested tags:
AWS , IAM , Security , Amazon EC2 , Amazon S3
This article is an educational example. Replace the sample bucket name and validate permissions for your own environment before deployment.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article