Assuming roles for temporary access in AWS - Time & Space Complexity
When using AWS roles for temporary access, it's important to understand how the time to get access changes as you request more roles.
We want to know how the number of role assumptions affects the total time taken.
Analyze the time complexity of the following operation sequence.
// Assume multiple roles sequentially
for (let i = 0; i < n; i++) {
sts.assumeRole({ RoleArn: roles[i], RoleSessionName: 'session' + i });
}
This code assumes a list of roles one after another to get temporary access credentials for each.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Calling the AWS STS AssumeRole API
- How many times: Once for each role in the list (n times)
Each additional role means one more call to assume that role, so the total calls grow directly with the number of roles.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls increases one-to-one with the number of roles.
Time Complexity: O(n)
This means the time to assume roles grows directly in proportion to how many roles you want to assume.
[X] Wrong: "Assuming multiple roles happens all at once, so time stays the same no matter how many roles."
[OK] Correct: Each role assumption is a separate call that takes time, so doing more roles takes more total time.
Understanding how the number of role assumptions affects time helps you design efficient access patterns and shows you can think about how cloud operations scale.
"What if we assumed roles in parallel instead of one after another? How would the time complexity change?"