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 →
- Create a role trusting
ec2.amazonaws.comwith a policy limited todynamodb:PutItemon the table ARN - Create an instance profile and attach it:
aws ec2 associate-iam-instance-profile --instance-id i-0abc --iam-instance-profile Name=orders-app - Use the default SDK credential chain in code, with no keys configured
- 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".
More on IAM, Organizations and Multi-Account
A developer needs read-only access to one S3 bucket from their laptop. How do you grant it without creating long-lived access keys?BeginnerSecurity wants to know who deleted a production S3 bucket yesterday. How do you find out?BeginnerYou must stop anyone in a member account from disabling CloudTrail, even account admins. What do you use?BeginnerA cross-account role assumption fails with AccessDenied even though the target role trusts the source account. What do you check?IntermediateDesign access for a CI pipeline in GitHub Actions to deploy to AWS without storing AWS keys in GitHub.IntermediateHow would you let developers create IAM roles for their apps without letting them escalate to admin?Intermediate