Learn about Security Token Service(STS) - AssumeRole with Terraform example
🔑 What is AWS Security Token Service (STS)?
AWS Security Token Service (STS) is an AWS service that issues temporary secuirty credentials for IAM users or roles. These credentials help reduce reliance on long-lived access keys and can be configured to follow the principle of least privilege. \
❓ Why use AWS STS?
With AssumeRole, You can avoid distributing long-lived access keys to users, applications, or AWS services.
Temporary credentials are safer because they expire automatically.
STS supports cross-account access without sharing permanent credentials.
It helps enforce least privilege by allowing you to assume only the permissions needed for a specific task.
Supports federation (SSO, OAuth)
⚙️ How AssumeRole works
A user, application, or AWS service requests to assume an IAM role.
AWS checks the role’s trust policy to determine whether the requester is allowed.
If allowed, STS returns temporary credentials:
Access key ID
Secret access key
Session token
The requester uses those temporary credentials to access AWS resources.
The credentials expire after the session duration.
🚀 Use Cases
Cross-account access
CI/CD Pipelines
AWS workloads: EKS, EC2, .. etc
Temporary elevated access
💻 Terraform Example
This example demonstrates a common STS-based access pattern: an EC2 instance receives temporary role credentials and uses them to access S3 securely without embedded access keys.