Quick Decision Rule: When An EC2, Lambda, or ECS workload needs programmatic access to AWS APIs, choose Attach a least-privilege IAM role using STS temporary credentials.
| Trigger Condition | An EC2, Lambda, or ECS workload needs programmatic access to AWS APIs |
|---|---|
| Recommended Choice | Attach a least-privilege IAM role using STS temporary credentials |
| Classic Trap | Embedding IAM user access keys in code, env files, or AMIs violates least privilege and increases credential leak blast radius. |
| Verification | Audited on 2026-11-23 · Guide v1.1 (2026-10-29) |
30-SECOND DECISION TRAP CHECK · SECURITY
An application running on EC2 instances needs read access to an S3 bucket. Which approach follows AWS security best practices?
IAM roles attached via instance profiles deliver auto-rotated temporary STS credentials with minimal scoped permissions.
Trap: Workloads on AWS should use IAM roles with temporary credentials, not long-lived access keys.