Interview Prep/AWS/IAM, Organizations and Multi-Account

An EC2 application needs to write to DynamoDB. Where do the credentials come from?

BeginnerScenarioIAM, Organizations and Multi-Account
Answer

Situation read → Never bake keys into the AMI or env vars; the instance should assume a role through its instance profile.

What I'd do →

  1. Create a role trusting ec2.amazonaws.com with a policy limited to dynamodb:PutItem on the table ARN
  2. Create an instance profile and attach it: aws ec2 associate-iam-instance-profile --instance-id i-0abc --iam-instance-profile Name=orders-app
  3. Use the default SDK credential chain in code, with no keys configured
  4. Enforce IMDSv2 so SSRF cannot trivially steal the role credentials

Why → The SDK fetches rotating credentials from IMDS automatically, so there is nothing to leak or rotate by hand.

Interview tip → Mention IMDSv2 HttpTokens=required; it shows security awareness beyond "use a role".

aws All AWS questions Roadmap: AWS core services

More on IAM, Organizations and Multi-Account