Security: IAM, Fine-Grained Access, and Encryption
DynamoDB has no database users or passwords — every request is an AWS API call authorised by IAM.
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) anddynamodb: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
DeleteTableuntil 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:
aws dynamodb update-table \--table-name ShopTable \--sse-specification Enabled=true,SSEType=KMS,KMSMasterKeyId=alias/shoptable-keyaws dynamodb update-table \--table-name ShopTable \--deletion-protection-enabled
Informative example
Customers can only read and write their own partition:
{"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
LeadingKeysfor 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:Scanto 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.
1IntermediateQuestionHow do you restrict a user to their own items in DynamoDB?+
Answer
2BeginnerQuestionWhat are the encryption-at-rest options?+
Answer
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.