IAM policy for DynamoDB - Time & Space Complexity
We want to understand how the time it takes to check permissions grows when using an IAM policy for DynamoDB.
Specifically, how does the number of permission checks change as the policy or requests grow?
Analyze the time complexity of evaluating this IAM policy for DynamoDB access.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["dynamodb:GetItem", "dynamodb:PutItem"],
"Resource": "arn:aws:dynamodb:region:account-id:table/ExampleTable"
}
]
}
This policy allows GetItem and PutItem actions on a specific DynamoDB table.
When a request is made, AWS checks the policy statements to decide if the action is allowed.
- Primary operation: Evaluating each statement in the policy against the request.
- How many times: Once per request, checking all statements until a match is found.
As the number of statements in the policy grows, the time to check permissions grows too.
| Input Size (n statements) | Approx. Permission Checks |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The number of checks grows directly with the number of statements.
Time Complexity: O(n)
This means the permission check time grows linearly with the number of policy statements.
[X] Wrong: "Permission checks happen instantly no matter how big the policy is."
[OK] Correct: Each statement must be checked in order, so bigger policies take more time.
Understanding how permission checks scale helps you design policies that keep your system fast and secure.
"What if the policy uses wildcards (*) in actions or resources? How would that affect the time complexity?"
Practice
Action element specify in an IAM policy for DynamoDB?Solution
Step 1: Understand the role of
TheActionin IAM policiesActionelement defines which DynamoDB operations (like read, write) are allowed or denied.Step 2: Differentiate from other policy elements
Other elements likeResourcespecify the table, butActioncontrols what can be done.Final Answer:
The allowed or denied DynamoDB operations -> Option AQuick Check:
Action = Allowed/Deny operations [OK]
- Confusing Action with Resource
- Thinking Action specifies table location
- Mixing Action with encryption or billing settings
Solution
Step 1: Identify correct ARN format for DynamoDB table
The ARN format for a DynamoDB table is: arn:aws:dynamodb:<region>::table/.Step 2: Compare options to the correct format
"Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/MyTable" matches the correct format exactly. "Resource": "arn:aws:s3:::mybucket" is for S3, C misses table name, D uses wrong resource type.Final Answer:
"Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/MyTable" -> Option BQuick Check:
Resource ARN for DynamoDB table = "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/MyTable" [OK]
- Using S3 ARN format instead of DynamoDB
- Omitting the table name in ARN
- Using 'database' instead of 'table' in ARN
{
"Effect": "Allow",
"Action": ["dynamodb:GetItem", "dynamodb:Query"],
"Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/Orders"
}Solution
Step 1: Analyze the Action list in the policy
The policy allows only "dynamodb:GetItem" and "dynamodb:Query", which are read operations.Step 2: Check the Resource and Effect
The resource is the Orders table only, and Effect is Allow, so only reading from Orders is allowed.Final Answer:
Only reading items from the Orders table -> Option CQuick Check:
Allowed actions = GetItem and Query (read) [OK]
- Assuming write or delete permissions are included
- Thinking policy applies to all tables
- Ignoring the Effect value
{
"Effect": "Allow",
"Action": "dynamodb:PutItem",
"Resource": "arn:aws:dynamodb:us-east-1:123456789012:table"
}Solution
Step 1: Check the Resource ARN format
The ARN ends with 'table' but does not specify the table name, so it does not point to any specific table.Step 2: Understand impact of incomplete ARN
Without a full ARN including the table name, the policy does not grant access to any resource.Final Answer:
Resource ARN is incomplete; missing table name -> Option AQuick Check:
Resource ARN must include table name [OK]
- Thinking Action must be an array always
- Confusing Effect Allow with Deny
- Assuming Condition is required for access
Solution
Step 1: Identify read permissions scope
Read actions (GetItem, Query) should apply to all tables, so Resource uses wildcard '*'.Step 2: Identify write permissions scope
Write action (PutItem) is limited to the 'Inventory' table only.Step 3: Match policy statements to requirements
{ "Effect": "Allow", "Action": ["dynamodb:GetItem", "dynamodb:Query"], "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/*" }, { "Effect": "Allow", "Action": ["dynamodb:PutItem"], "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/Inventory" } correctly separates read and write permissions with proper Resource ARNs.Final Answer:
Separate statements: read on all tables, write only on Inventory -> Option DQuick Check:
Read = all tables, Write = Inventory only [OK]
- Granting write access to all tables
- Mixing read and write on wrong resources
- Using wildcard for write when not intended
Ready to prove it?
Pass the test and this pattern moves unknown
