You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
AWS Security Token Service (STS) is the engine behind temporary credentials in AWS. Every time you assume a role, federate an external identity, or request session tokens, STS is doing the work. Understanding STS is essential for building secure architectures.
STS is a global web service that provides temporary, limited-privilege security credentials. These credentials consist of three parts:
| Component | Description |
|---|---|
| Access Key ID | Identifies the temporary credential |
| Secret Access Key | Used to sign requests |
| Session Token | Must be included with every request using temporary credentials |
Temporary credentials work almost identically to permanent access keys, except:
Temporary credentials are a cornerstone of AWS security best practices:
STS provides several API actions, each serving a different use case:
The most commonly used STS action. It returns temporary credentials for an IAM role.
aws sts assume-role \
--role-arn arn:aws:iam::123456789012:role/MyRole \
--role-session-name my-session \
--duration-seconds 3600
Use cases:
Duration: 15 minutes to 12 hours (default: 1 hour).
Returns temporary credentials for users authenticated via a SAML 2.0 identity provider (e.g., Active Directory Federation Services, Okta, OneLogin).
Use case: Enterprise single sign-on (SSO) — employees authenticate with their corporate credentials and receive AWS access without needing IAM users.
Duration: 15 minutes to 12 hours.
Returns temporary credentials for users authenticated by a web identity provider (e.g., Login with Amazon, Facebook, Google, or any OpenID Connect provider).
Use case: Mobile or web applications where end users authenticate with a social identity provider to access AWS resources (like uploading to S3).
Note: AWS recommends using Amazon Cognito instead of calling this API directly, as Cognito provides a higher-level abstraction.
Duration: 15 minutes to 12 hours.
Returns temporary credentials for an IAM user. This is typically used to enable MFA-protected API access.
aws sts get-session-token \
--serial-number arn:aws:iam::123456789012:mfa/my-user \
--token-code 123456 \
--duration-seconds 3600
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.