Fine-grained access control lets you decide exactly who can see or change each piece of data. It helps keep your data safe and private.
When you want users to only see their own data in a shared database.
When different users have different permissions for parts of the data.
When you want to limit access to sensitive information like personal details.
When you want to control who can update or delete specific records.
When you need to follow rules or laws about data privacy.
Syntax
DynamoDB
Use IAM policies with condition keys like dynamodb:LeadingKeys or dynamodb:Attributes to control access.
Example:
{
"Effect": "Allow",
"Action": "dynamodb:GetItem",
"Resource": "arn:aws:dynamodb:region:account-id:table/TableName",
"Condition": {
"ForAllValues:StringEquals": {
"dynamodb:LeadingKeys": ["${aws:username}"]
}
}
}
Fine-grained access control is set using IAM policies with special DynamoDB condition keys.
The dynamodb:LeadingKeys condition limits access to items with partition keys matching the user's identity.
Examples
This policy lets a user read only the orders where the partition key matches their username.
This IAM policy allows a user to get items from the Tasks table only if the partition key matches their username. This means users can only read their own tasks.
A. Action should be dynamodb:Query instead of GetItem
B. Resource ARN is incorrect
C. Effect should be Deny instead of Allow
D. Condition should use ForAllValues:StringEquals with an array
Solution
Step 1: Check condition syntax for dynamodb:LeadingKeys
The condition expects an array with ForAllValues:StringEquals, not a single string with StringEquals.
Step 2: Understand impact of incorrect condition
Using StringEquals with a string causes the condition to be ignored, allowing broader access.
Final Answer:
Condition should use ForAllValues:StringEquals with an array -> Option D
Quick Check:
Use ForAllValues:StringEquals and array for LeadingKeys [OK]
Hint: Use ForAllValues:StringEquals with array for LeadingKeys [OK]
Common Mistakes:
Using StringEquals with a string instead of array
Incorrect ARN format
Confusing action types
Changing Effect to Deny unnecessarily
5. You want to allow users to read only their own orders in a DynamoDB table where the partition key is 'UserId'. Which IAM policy condition correctly enforces this fine-grained access control for user 'alice'?
hard
A. { "ForAllValues:StringEquals": { "dynamodb:LeadingKeys": ["alice"] } }
B. { "StringEquals": { "dynamodb:Attributes": ["alice"] } }
C. { "ForAnyValue:StringEquals": { "dynamodb:LeadingKeys": ["alice"] } }
D. { "StringLike": { "dynamodb:LeadingKeys": "alice*" } }
Solution
Step 1: Identify correct condition operator for exact key match
For fine-grained access, ForAllValues:StringEquals with an array ensures all keys match exactly.
Step 2: Evaluate options for correct syntax and semantics
{ "ForAllValues:StringEquals": { "dynamodb:LeadingKeys": ["alice"] } } uses correct operator and array format; others use wrong keys or operators.
Final Answer:
{ "ForAllValues:StringEquals": { "dynamodb:LeadingKeys": ["alice"] } } -> Option A
Quick Check:
Exact key match needs ForAllValues:StringEquals with array [OK]
Hint: Use ForAllValues:StringEquals with array for exact user keys [OK]
Common Mistakes:
Using dynamodb:Attributes instead of LeadingKeys
Using StringEquals without array
Using StringLike which allows wildcards
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.