Skip to main content
AWS Beginner Core Concept Q&A Topic: IAM Identity & Least Privilege

Explain AWS IAM roles, policies, and why roles are safer than access keys

Quick Summary: An IAM Policy is a JSON document declaring allowed or denied actions on AWS resources, whereas an IAM Role is an assumable identity issuing short-lived temporary STS credentials automatically rotated without static access keys.

Written by Ravi Shankar Mishra (Founder & Lead Systems Architect, MockAttempt Academy) Reviewed by MockAttempt Engineering Editorial Desk
Last verified:

Direct Interview Answer

IAM Policies evaluate permissions using explicit deny → explicit allow → default implicit deny logic. An explicit Deny always overrides any Allow.

IAM Roles define a Trust Policy (who can assume the role—EC2, Lambda, ECS, or cross-account principals) and Permission Policies (what the role can call), eliminating hardcoded long-lived AWS access keys.

Detailed Technical Explanation

On EC2 or EKS, Instance Profiles / IRSA automatically fetch rotating short-lived tokens from AWS STS, meaning even if application logs leak temporarily, stale credentials expire cleanly.

Practical Walkthrough

Least-privilege S3 bucket write policy scoped strictly to one invoice prefix.

Code Example — JSON
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["s3:PutObject", "s3:GetObject"],
      "Resource": "arn:aws:s3:::mockattempt-invoices-prod/2026/*"
    }
  ]
}
Expected Output / Verification
Only PutObject and GetObject permitted strictly inside the 2026/* prefix.

Real-World Production Use Case

Granting ECS Fargate microservices least-privilege access to S3 uploads and Secrets Manager without placing AWS_ACCESS_KEY_ID inside .env files.

Common Interview Mistakes to Avoid

  • Granting wildcard "*" on both Action and Resource inside production roles.
  • Confusing IAM Role Permissions Policy (what it can do) with Trust Policy (who can assume it).
Topics: #aws #iam #security #sts #saa-c03
Learn. Practise. Prove. Get Career-Ready.

Ready to Build Your IT Career?

Explore industry-led programmes and develop practical skills through training, assessments and interview preparation.