Easy👤 0-2 years👤 3-5 years 1 min read

IAM users vs roles vs policies — how do you grant an app access to AWS without hardcoding keys?

Asked inAmazonTCSCognizantWipro
#iam#roles#policies#least privilege#credentials
Report issue

⚡ Short Answer

A user is a long-lived identity with credentials (for humans). A role is an identity apps/services ASSUME to get temporary credentials — no stored keys. A policy is the JSON that grants permissions. Give EC2/Lambda an IAM role, never embed access keys.

Coffee Chat Question

Concept Made Simple

IAM users vs roles vs policies — how do you grant an app access to AWS without hardcoding keys?

🧠Mind Map Answer

Remember It Faster

Userlong-lived identity (humans/CI)
Roleassumed → temporary creds (apps)
PolicyJSON permissions (allow/deny)

⌨️Hands-on Keyboard

Learn by Doing

json
{ "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:GetObject"],
    "Resource": "arn:aws:s3:::my-bucket/*"
  }] }

🔥What If?

Think Beyond the Expected

Why is attaching an IAM role to EC2/Lambda better than storing an access key in config?

A role delivers short-lived, auto-rotating temporary credentials via the instance/execution environment — nothing to leak or rotate manually. Hardcoded keys get committed to repos, logged, and never expire, which is a top cause of AWS breaches.

😂Real World

Leaked long-lived access keys (in git) are one of the most common AWS security incidents; roles + least-privilege policies are the standard, credential-free way to grant access.

🎯Interviewer's Expectation

Keywords they're listening for:

user vs role vs policyroles = temporary credsattach role to serviceleast privilegeno hardcoded keys

⚠️Common Mistakes

  • Hardcoding access keys in code/config
  • Over-broad policies (Action: '*')
  • Using the root account for daily work

Best Practices

  • Use roles for services; least-privilege policies
  • No long-lived keys in apps
  • Lock down and MFA the root account

🔁Follow-up Questions

  • 1What is least privilege and how do you achieve it?
  • 2How do temporary credentials from a role rotate?
  • 3Difference between identity-based and resource-based policies?

🧩Related Technologies

STSinstance profileIAM Access Analyzer

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: IAM (AWS)
Interview question: "IAM users vs roles vs policies — how do you grant an app access to AWS without hardcoding keys?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Support our platform by exploring our recommended products.

As an Amazon affiliate, purchases through these links may earn us a small commission — at no extra cost to you. It helps keep Full Stack Interview Guru free.

Related Questions