Why IAM policies protect data in DynamoDB - Performance Analysis
We want to understand how the time it takes to check permissions grows as more users and policies are involved.
How does the system handle permission checks efficiently to protect data?
Analyze the time complexity of checking IAM policies for a DynamoDB request.
// Simplified IAM policy check pseudocode
function checkAccess(user, action, resource) {
for (const policy of user.policies) {
if (policy.allows(action, resource)) {
return true;
}
}
return false;
}
This code checks each policy attached to a user to see if it allows the requested action on the resource.
Look for repeated steps in the code.
- Primary operation: Looping through all policies attached to the user.
- How many times: Once for each policy the user has.
As the number of policies grows, the time to check permissions grows too.
| Input Size (number of policies) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The time grows directly with the number of policies to check.
Time Complexity: O(n)
This means the time to check permissions grows linearly with the number of policies a user has.
[X] Wrong: "Checking IAM policies is instant no matter how many policies exist."
[OK] Correct: Each policy must be checked one by one until a match is found, so more policies mean more checks and more time.
Understanding how permission checks scale helps you explain how secure systems stay fast even as they grow.
"What if policies were indexed by action and resource? How would that change the time complexity?"