IAM
IAM (Identity and Access Management) decides who can do what in your AWS account. Every API call is checked against IAM policies.
On this page · 5 min · Beginner
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 29, 2026
Related tutorials
Learning objectives#
- Explain users, groups, roles and policies
- Read and write a JSON policy
- Apply least privilege
- Use roles for applications
Explanation#
A policy is a JSON document of statements: Effect (Allow/Deny), Action (s3:GetObject), Resource (an ARN) and optional Condition.
By default everything is denied. An explicit Allow grants access; an explicit Deny always wins.
Roles are identities with temporary credentials that are assumed — by an EC2 instance, a Lambda function, an ECS task, a GitHub Actions workflow or a person.
Applications should use roles, never long-lived access keys embedded in code.
Code example: Least-privilege policy for one bucket folder#
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadWriteProductImages",
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::shop-assets-123/products/*"
},
{
"Sid": "ListOnlyProductsPrefix",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::shop-assets-123",
"Condition": { "StringLike": { "s3:prefix": ["products/*"] } }
}
]
}
An app with this policy can read, upload and list files under products/ in one bucket — and nothing else in the account.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Version 2012-10-17 is the current policy language version.
- The first statement allows reading and writing objects under one prefix.
- ListBucket applies to the bucket ARN itself, limited by a prefix condition.
- Everything not allowed is implicitly denied.
Real-world use case#
An EC2 instance role carries this policy, so the Node.js API on that instance can upload product images without any keys in its configuration.
Common mistakes#
Full admin for an app means one bug or leak compromises everything.
Bots scan public repos for AWS keys within minutes. Use roles; rotate or delete any leaked key immediately.
Best practices#
- Grant least privilege and refine with IAM Access Analyzer
- Use roles for workloads
- Assign permissions to groups or permission sets, not individuals
- Require MFA for humans
Remember this#
Default deny → explicit Allow → explicit Deny always wins.
Policy = Effect + Action + Resource (+ Condition).
Apps use roles. No keys in code.
Practice exercise#
Your task: Write a policy statement that allows only reading items from the DynamoDB table Orders (GetItem and Query).
Show solution
{
"Effect": "Allow",
"Action": ["dynamodb:GetItem", "dynamodb:Query"],
"Resource": "arn:aws:dynamodb:ap-south-1:123456789012:table/Orders"
}
Mini quiz#
If one policy allows s3:DeleteObject and another explicitly denies it, what happens?
Want more? Practise all AWS MCQs · AWS interview questions
My notes#
Saved in this browser.