0
0
DynamoDBquery~20 mins

Fine-grained access control in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Fine-grained Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this DynamoDB query with fine-grained access control?

Consider a DynamoDB table Orders with items having attributes OrderID, UserID, and Status. A fine-grained access control policy restricts users to see only orders where UserID matches their own ID.

The following query is run by user with UserID = 'user123':

Scan Orders with FilterExpression: UserID = :uid
ExpressionAttributeValues: { ':uid': 'user123' }

Given the table data:

  • {OrderID: 1, UserID: 'user123', Status: 'shipped'}
  • {OrderID: 2, UserID: 'user456', Status: 'pending'}
  • {OrderID: 3, UserID: 'user123', Status: 'delivered'}

What will be the result of this query?

A[{OrderID: 1, UserID: 'user123', Status: 'shipped'}, {OrderID: 3, UserID: 'user123', Status: 'delivered'}]
B[{OrderID: 1, UserID: 'user123', Status: 'shipped'}, {OrderID: 2, UserID: 'user456', Status: 'pending'}, {OrderID: 3, UserID: 'user123', Status: 'delivered'}]
C[]
D[{OrderID: 2, UserID: 'user456', Status: 'pending'}]
Attempts:
2 left
💡 Hint

Think about which items match the filter expression for the user's ID.

🧠 Conceptual
intermediate
1:30remaining
Which DynamoDB feature enables fine-grained access control at the item level?

Which of the following DynamoDB features allows you to restrict user access to specific items based on their attributes?

AProvisioned Throughput settings
BDynamoDB Streams
CGlobal Secondary Indexes
DIAM policies with condition keys on item attributes
Attempts:
2 left
💡 Hint

Think about how AWS IAM can control access based on item content.

📝 Syntax
advanced
2:30remaining
Which IAM policy snippet correctly restricts access to items with partition key 'UserID' equal to the user's ID?

Given a DynamoDB table with partition key UserID, which IAM policy snippet correctly enforces fine-grained access control so that users can only access their own items?

A{ "Effect": "Allow", "Action": "dynamodb:GetItem", "Resource": "arn:aws:dynamodb:region:account-id:table/Orders" }
B{ "Effect": "Allow", "Action": "dynamodb:GetItem", "Resource": "arn:aws:dynamodb:region:account-id:table/Orders", "Condition": { "ForAllValues:StringEquals": { "dynamodb:LeadingKeys": "${aws:username}" } } }
C{ "Effect": "Allow", "Action": "dynamodb:Query", "Resource": "arn:aws:dynamodb:region:account-id:table/Orders", "Condition": { "StringEquals": { "dynamodb:Attributes": "UserID" } } }
D{ "Effect": "Allow", "Action": "dynamodb:Scan", "Resource": "arn:aws:dynamodb:region:account-id:table/Orders", "Condition": { "StringEquals": { "dynamodb:LeadingKeys": "user123" } } }
Attempts:
2 left
💡 Hint

Look for the condition that matches the partition key to the user's identity dynamically.

🔧 Debug
advanced
2:30remaining
Why does this fine-grained access control policy fail to restrict access properly?

A developer wrote this IAM policy to restrict access to items with UserID matching the user's ID, but users can still access all items:

{
  "Effect": "Allow",
  "Action": "dynamodb:GetItem",
  "Resource": "arn:aws:dynamodb:region:account-id:table/Orders",
  "Condition": {
    "StringEquals": {
      "dynamodb:LeadingKeys": "user123"
    }
  }
}

Why does this policy fail to enforce fine-grained access control?

AThe resource ARN is missing the index specification required for fine-grained access control.
BThe action 'dynamodb:GetItem' does not support conditions on 'dynamodb:LeadingKeys'.
CThe condition uses a fixed value 'user123' instead of a variable, so it only allows access to that user, but others are unrestricted.
DThe policy is missing the 'Effect': 'Deny' statement to block other accesses.
Attempts:
2 left
💡 Hint

Consider how the condition value affects different users.

optimization
expert
3:00remaining
How to optimize fine-grained access control for a DynamoDB table with multiple user roles?

You have a DynamoDB table Documents with items containing DocID, OwnerID, and Role attributes. You want to enforce fine-grained access control so that:

  • Owners can read and write their own documents.
  • Users with role 'editor' can read all documents but write only their own.
  • Users with role 'viewer' can only read documents they own.

Which approach best optimizes this access control using IAM policies?

ACreate separate IAM policies for each role using condition keys on <code>OwnerID</code> and <code>Role</code> attributes with <code>dynamodb:LeadingKeys</code> and <code>dynamodb:Attributes</code> conditions.
BUse a single IAM policy allowing all actions on the table and enforce access control only in application code.
CGrant full table access to all users and rely on DynamoDB Streams to audit unauthorized access.
DUse Global Secondary Indexes to separate documents by role and assign policies based on index access.
Attempts:
2 left
💡 Hint

Think about how IAM policies can use conditions to differentiate roles and ownership.