Understanding AWS Identity Management Through Office Building Security
If you've ever worked in a corporate office building, you've probably used an access card to get through doors. AWS IAM (Identity and Access Management) works exactly like this corporate access card system - but instead of physical doors, you're controlling access to cloud services and data.
Imagine you work for a tech company called "CloudCorp" in a fancy office building:
IAM Users are like permanent employees. Each person gets their own identity and access card.
Example team setup:
{
"Users": [
{
"Name": "sarah.marketing",
"Access": "Marketing content and analytics only"
},
{
"Name": "mike.devops",
"Access": "Server management and deployment"
},
{
"Name": "alex.developer",
"Access": "Development environment only"
}
]
}
When to use IAM Users:
When NOT to use IAM Users:
IAM Roles are like temporary visitor passes that:
The Visiting Consultant: External security consultant needs 2-week access. Instead of a permanent badge:
The Automated Service: Your EC2 instance needs to upload files to S3:
{
"RoleName": "EC2-S3-Upload-Role",
"AssumedBy": "ec2.amazonaws.com",
"Permissions": ["s3:PutObject on uploads bucket only"]
}
1. Service Roles (Most Common):
{
"EC2Role": {
"Purpose": "Let EC2 instances access S3",
"AssumedBy": "ec2.amazonaws.com",
"Benefits": ["No hardcoded keys", "Automatic rotation", "Better security"]
}
}
2. Cross-Account Roles:
{
"CrossAccountRole": {
"Purpose": "Let developers from Account A access Account B",
"AssumedBy": "arn:aws:iam::ACCOUNT-A:root",
"Condition": "Must know secret external ID",
"Benefits": ["Secure cross-account access", "No shared credentials"]
}
}
When to use Roles:
Policies are detailed instructions on each access card that specify exactly what doors you can open.
Policy anatomy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": ["arn:aws:s3:::company-docs/*"],
"Condition": {
"StringEquals": {
"aws:RequestedRegion": "us-west-2"
}
}
}
]
}
Translation: "Allow reading files from 'company-docs' S3 bucket, but only from us-west-2 region."
Read-Only Analyst:
{
"Effect": "Allow",
"Action": ["s3:GetObject", "cloudwatch:Get*", "logs:Describe*"],
"Resource": "*"
}
Cost-Conscious Developer:
{
"Effect": "Allow",
"Action": ["ec2:RunInstances"],
"Condition": {
"StringEquals": {
"ec2:InstanceType": ["t3.micro", "t3.small"]
}
}
}
FoodieApp team structure:
{
"TeamStructure": {
"Humans": [
{"john.cto": "AdminAccess policy"},
{"sarah.frontend": "FrontendDevelopers group"},
{"mike.backend": "BackendDevelopers group"}
],
"Applications": [
{"ProductionServers": "EC2-S3-Access role"},
{"EmailService": "Lambda-SES-Send role"}
],
"Groups": [
{"FrontendDevelopers": "S3 website access + CloudFront"},
{"BackendDevelopers": "RDS + Lambda + API Gateway"}
]
}
}
Wrong:
{"Effect": "Allow", "Action": "*", "Resource": "*"}
Why dangerous:
Better:
{
"Effect": "Allow",
"Action": ["ec2:*", "s3:*"],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:RequestedRegion": "us-west-2",
"aws:ResourceTag/Environment": "Development"
}
}
}
Wrong:
const s3 = new AWS.S3({
accessKeyId: 'AKIAIOSFODNN7EXAMPLE',
secretAccessKey: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
});
Better:
// Use IAM roles - no hardcoded keys!
const s3 = new AWS.S3(); // Automatically uses EC2 instance role
Problem: Long-lived keys increase security risk
Solution: Automated rotation every 90 days:
# Create new key, update app, test, delete old key
aws iam create-access-key --user-name api-user
# Update application configuration
# Test functionality
aws iam delete-access-key --user-name api-user --access-key-id OLD_KEY
1. Wrong instance types allowed:
{"Mistake": "Developer launches c5.24xlarge instead of c5.large"}
{"Cost": "$4,000/month instead of $70/month"}
{"Solution": "Restrict instance types in policy"}
2. Cross-region data transfer:
{"Mistake": "Policy allows S3 access from any region"}
{"Cost": "Unexpected $500/month data transfer charges"}
{"Solution": "Restrict to specific regions in policy conditions"}
Environment restrictions:
{
"DevelopmentPolicy": {
"AllowedInstances": ["t3.micro", "t3.small only"],
"AllowedRegions": ["us-west-2 only"],
"RequiredTags": ["Environment=Development"],
"TimeRestrictions": "No launches outside business hours"
}
}
Understanding IAM is like learning a building's security system - complex at first, but essential for safety and efficiency:
The investment in proper IAM setup pays dividends in reduced security incidents, lower AWS bills, and better operational efficiency.
Need help implementing cost-conscious IAM policies alongside resource optimization? Huskar respects your IAM boundaries while automatically scheduling non-critical resources to reduce costs. Our IAM-aware automation never overrides your security policies. Try our free tier to see how intelligent scheduling works within your permission framework.
AWS, IAM, Security, Roles, Users, Policies, Access Management, Cost Optimization, ELI5