Amazon DynamoDB Tutorial 0/30 lessons ~6 min read Lesson 27

    Security: IAM, Fine-Grained Access, and Encryption

    DynamoDB has no database users or passwords — every request is an AWS API call authorised by IAM.

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    DynamoDB has no database users or passwords — every request is an AWS API call authorised by IAM. That makes security a matter of precise IAM policies, network controls, and encryption key choices. Fine-grained access control can even restrict a caller to items whose partition key matches their identity.

    Purpose of this lesson

    You will write least-privilege policies, restrict access to a user's own items with dynamodb:LeadingKeys, choose an encryption key, and protect tables from accidental deletion.

    Understanding the topic

    Security controls:

    • IAM identity policies grant actions (dynamodb:GetItem, dynamodb:Query, …) on table and index ARNs.
    • Fine-grained access control: condition keys dynamodb:LeadingKeys (partition key values) and dynamodb:Attributes (attribute names).
    • Resource-based policies on tables and streams enable cross-account access without assuming roles.
    • Encryption at rest is always on, using an AWS owned key (default), the AWS managed key aws/dynamodb, or a customer managed KMS key you control and audit.
    • Network: a VPC gateway endpoint keeps traffic on the AWS network; policies can require aws:SourceVpce.
    • Deletion protection blocks DeleteTable until it is turned off.
    • CloudTrail records control-plane calls by default; enable data events to audit item-level access.

    Syntax reference

    Customer managed key and deletion protection:

    bash
    aws dynamodb update-table \
    --table-name ShopTable \
    --sse-specification Enabled=true,SSEType=KMS,KMSMasterKeyId=alias/shoptable-key
    aws dynamodb update-table \
    --table-name ShopTable \
    --deletion-protection-enabled

    Informative example

    Customers can only read and write their own partition:

    json
    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Sid": "OwnItemsOnly",
    "Effect": "Allow",
    "Action": ["dynamodb:GetItem", "dynamodb:Query", "dynamodb:PutItem", "dynamodb:UpdateItem"],
    "Resource": "arn:aws:dynamodb:us-east-1:123456789012:table/ShopTable",
    "Condition": {
    "ForAllValues:StringEquals": {
    "dynamodb:LeadingKeys": ["CUSTOMER#${aws:PrincipalTag/customerId}"]
    }
    }
    }
    ]
    }

    The caller's session carries a customerId principal tag (for example from Cognito or an identity provider). Any request whose partition key is a different customer's is denied.

    Best practices

    • Grant per-service roles only the actions and indexes they use; avoid dynamodb:*.
    • Use LeadingKeys for multi-tenant or per-user access from client-side credentials.
    • Use a customer managed KMS key when you need key policies, rotation control, or key-usage audit.
    • Enable deletion protection and PITR on every production table.

    Common mistakes

    • Granting dynamodb:Scan to roles that only need Query — Scan bypasses partition-scoped thinking.
    • Forgetting index ARNs (table/ShopTable/index/*) in policies, causing AccessDenied on GSI queries.
    • Putting secrets or full card numbers in items when tokenisation is required.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    2 questions
    1IntermediateQuestionHow do you restrict a user to their own items in DynamoDB?+

    Answer

    Use an IAM condition on dynamodb:LeadingKeys so the partition key in every request must equal a value derived from the caller's identity (for example a principal tag or Cognito identity id).
    2BeginnerQuestionWhat are the encryption-at-rest options?+

    Answer

    Encryption at rest is always enabled. You choose the key: an AWS owned key (no charge, no visibility), the AWS managed key aws/dynamodb, or a customer managed KMS key with your own key policy and CloudTrail auditing of key use.

    Hands-on exercise

    Hands-on: write an IAM policy for an order-fulfilment service that may Query GSI1 and UpdateItem on order headers only (dynamodb:Attributes limited to status and version). Test it with the IAM policy simulator.

    Summary

    DynamoDB security is IAM-first: least-privilege actions, LeadingKeys for per-user isolation, VPC endpoints, a deliberate KMS key choice, deletion protection, and CloudTrail data events.

    Ready to mark this lesson complete?Track your journey across the entire course.