AWS for developers · Concept
How your service gets AWS credentials
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Your service runs on AWS and needs to read files from S3 and send messages to SQS. How does the code get AWS credentials, and why shouldn't you just put an access key in its environment variables?
Then
Follow-ups the interviewer asks next
- When the SDK starts, where does it look for credentials, and in what order?
- On ECS, what's the difference between the task role and the task execution role?
- On EKS, how does one pod get its own permissions: IRSA or EKS Pod Identity?
- How do you work with AWS from your laptop without a long-lived key?
- The service gets AccessDenied in production but works from your laptop. How do you debug it?
- Is there any case where an access key still makes sense?
The answer
What a strong answer covers
- Give the compute an IAM role; the SDK fetches short-lived credentials from STS and refreshes them itself. EC2: instance profile through the metadata service (IMDSv2). ECS and Fargate: task role. Lambda: execution role. EKS: EKS Pod Identity or IRSA.
- The default credential chain checks environment variables first, then shared config and SSO profiles, web identity tokens, the container credentials endpoint and the instance metadata service. A leftover key in the environment silently wins over the role.
- ECS task execution role: what ECS itself needs (pull from ECR, write logs, fetch secrets it injects). Task role: what your code calls. Mixing them gives the app more power than it needs.
- EKS Pod Identity is AWS's recommended way on EKS today: no OIDC provider per cluster and one role reusable across clusters. IRSA still works and is the option for self-managed Kubernetes.
- Long-lived keys leak through logs, images, Git and laptops, never expire, and can't be tied to one workload. On a laptop, use IAM Identity Center (
aws sso login) or the CLI's console sign-in (aws login), both short-lived. - Debugging AccessDenied: run
aws sts get-caller-identityfrom inside the workload, read the error (it names the action and often the policy type that blocked it), check CloudTrail, then resource policies (bucket policy, KMS key policy), SCPs and permission boundaries. - Keys only where no role is possible (a partner's on-prem system), with one key per system, least privilege, rotation and monitoring; IAM Roles Anywhere is the better answer there.
The red pen
Common traps
Avoid:"keys in .env, and .env is in .gitignore"; not knowing the task role from the execution role; thinking a role is a user with a stored key.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.