AWS IAM Roles and Trust Policies
What You'll Learn
You'll learn how IAM roles use trust policies to let AWS services and accounts temporarily assume permissions.
Why Roles Need Trust Policies
An IAM role is like a security badge that can be worn by different entities (EC2 instances, Lambda functions, other AWS accounts). Unlike IAM users, roles don't have permanent credentials. Instead, they grant temporary access.
But here's the key question: who is allowed to wear that badge?
That's where trust policies come in.
What is a Trust Policy?
A trust policy (also called an "assume role policy") defines who can assume the role. Think of it as the bouncer at the door—it checks credentials and decides who's allowed in.
When you create a role, you attach:
- Trust policy – who can use this role
- Permissions policy – what the role can do once assumed
How It Works
Imagine you create a role called EC2-Read-S3-Role:
- Trust policy says: "EC2 service can assume this role"
- Permissions policy says: "Read access to S3 buckets"
When your EC2 instance starts, it can assume this role and get temporary credentials to read from S3—without storing long-term access keys on the instance.
Common Use Cases
- EC2 instances accessing S3 or databases
- Lambda functions calling other AWS services
- Cross-account access (Account A trusts Account B)
- Service-to-service communication
Key Components
A trust policy specifies the Principal (who can assume) and Action (sts:AssumeRole). The trusted entity gets temporary credentials valid for a session.
Key Takeaway: Trust policies control who can wear the role; permissions policies control what the role can do. Together they enable secure, temporary access without permanent credentials.