AssumeRole and the Session Lifetime
Learn how a principal trades its identity for role permissions.
AssumeRole and the Session Lifetime is a free AWS Security Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Trading Identity for Permissions
The AssumeRole operation lets a principal temporarily exchange its own identity for a role's permissions. The result is a time-bounded session. Controlling how long that session lasts, and how its permissions are scoped, is a frequent SCS-C02 topic because session lifetime directly affects security exposure.
The Assumed-Role Session
After AssumeRole succeeds, the caller operates as an assumed-role session, identified by an ARN like arn:aws:sts::ACCOUNT:assumed-role/RoleName/SessionName. For the duration, the caller has the role's permissions and not their original ones. The session name you pass is preserved for auditing.
Duration Seconds
The DurationSeconds parameter sets how long the session lasts, from 900 seconds (15 minutes) up to a maximum defined by the role. Shorter sessions reduce the window during which leaked credentials are valid, so least-privilege thinking favors the shortest practical duration.
The Maximum Session Duration
Each role has a MaximumSessionDuration setting (1 to 12 hours). A request for DurationSeconds longer than this is rejected. Setting a sensible maximum on sensitive roles caps how long any single assumption can last, a control you can tune for high-risk roles.
Role Chaining Limit
When one assumed role assumes another role, that is role chaining. AWS limits chained sessions to a maximum of one hour, regardless of the role's configured maximum. Recognizing this cap explains why some long-duration requests fail when roles are chained, a subtle exam detail.
Refreshing Credentials
Because sessions expire, applications must re-assume the role to keep working. SDKs handle this transparently for instance profiles and configured role profiles, fetching new credentials before the old ones expire. There is no way to extend an existing session; you simply obtain a fresh one.
AssumeRole Parameters
Beyond duration, AssumeRole accepts Policy or PolicyArns (session policies to narrow permissions), Tags (session tags for ABAC), and SerialNumber plus TokenCode for MFA. These let you scope and protect each assumption precisely at the moment it happens.
Requiring MFA
A role's trust policy can require MFA, in which case AssumeRole must include the MFA device ARN and a current token code. This ensures a privileged role cannot be assumed by a stolen credential alone. Pairing short sessions with MFA is a strong, exam-endorsed control for sensitive roles.
"Condition": {
"Bool": { "aws:MultiFactorAuthPresent": "true" }
}Revoking Active Sessions
You cannot delete an individual temporary credential, but you can revoke all active sessions for a role by attaching an inline policy that denies actions for tokens issued before a chosen time, using the aws:TokenIssueTime condition. The console "Revoke active sessions" button does exactly this, a key incident-response tool.
Why Short Sessions Help
Short session lifetimes mean that even if temporary credentials leak, they soon become useless. Combined with revocation, MFA, and least-privilege session policies, they shrink the attack window dramatically. The exam favors answers that minimize how long any credential remains valid.
Putting It Together
AssumeRole creates a time-bounded session governed by DurationSeconds within the role's MaximumSessionDuration, with chained roles capped at one hour. Scope each session with policies, tags, and MFA, and use the TokenIssueTime revocation trick to kill compromised sessions instantly. Short, scoped sessions are the secure default.
Quick Check
Test session-lifetime knowledge.
Recap
AssumeRole creates an assumed-role session lasting from 15 minutes up to the role's MaximumSessionDuration (max 12 hours), with role chaining capped at one hour. Scope sessions with session policies, tags, and MFA. Revoke compromised sessions using the aws:TokenIssueTime deny trick. Prefer short, scoped sessions.
Frequently asked questions
Is the “AssumeRole and the Session Lifetime” lesson free?
Yes — the full text of “AssumeRole and the Session Lifetime” is free to read here on the web, and the AWS Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “AssumeRole and the Session Lifetime”?
Learn how a principal trades its identity for role permissions. You practise AWS Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Security Academy?
No prior experience is required. AWS Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “AssumeRole and the Session Lifetime” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Security Academy lesson?
Yes. Every AWS Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- How STS Issues Temporary Credentials
- AssumeRole and the Session Lifetime
- External ID and the Confused Deputy
- Session Policies and Tag-Based Scoping