DynamoDB Just Made Your Life Easier: Multi-Attribute Composite Keys Explained
AWS just dropped a feature on November 19, 2025 that is going to save you from one of DynamoDB’s most annoying workarounds: multi-attribute composite keys for Global Secondary Indexes (GSIs). Let me show you why this matters with a real-world example.
Important: This is a GSI Feature
Critical Clarification: This new capability applies to Global Secondary Indexes (GSIs) only - NOT to your base table’s primary key. Your base table still uses the traditional structure of a single partition key + optional single sort key. However, when you create GSIs on your table, you can now use up to 4 partition key attributes and 4 sort key attributes!

The Scenario: E-Commerce Order Tracking
Imagine you are building an order management system. You need to query orders by:
- Customer ID + Order Date + Order Status
Seems simple, right? Wrong. Until now, this was a pain.
The Old Way (aka The Painful Way)
Before this update, you had two bad options:
Option 1: Concatenate Fields (Yuck!)
GSI Configuration:
Partition Key: customer_id
Sort Key: date_status (concatenated: "2024-11-24_SHIPPED")
This meant:
- Extra fields cluttering your table
- String manipulation everywhere in your code
- Maintenance nightmares when requirements change
- Code that looks like
sortKey =${date}_${status}``
Option 2: Full Table Scan (Nope!)
Just scan the entire table filtering by all three fields. Slow, expensive, and scales terribly.
The New Way (Hello, Beautiful!)
Now you can do this with your GSI:
Global Secondary Index Configuration:
Partition Key: customer_id
Sort Key 1: order_date
Sort Key 2: order_status
Up to 4 partition key fields and 4 sort key fields per GSI!
What This Means for You
// Before: String concatenation madness
const sortKey = `${orderDate}_${status}`;
// After: Clean, intuitive queries on your GSI
queryParams = {
IndexName: 'CustomerOrdersIndex',
partitionKey: customerId,
sortKey1: orderDate,
sortKey2: status
}
Real Benefits:
- Cleaner Code: No more string concatenation hacks
- Better Performance: Query (not scan) with multiple attributes on GSIs
- Easier Maintenance: Add/remove query patterns without refactoring
- Native Support: Let DynamoDB handle the complexity
- Native Data Types: Keep numbers as numbers, dates as dates - no string conversion needed

Quick Example
Let us say you need to find all orders for customer “C123” placed on “2024-11-24” with status “PENDING”:
Before:
# Had to concatenate
sort_key = f"2024-11-24_PENDING"
response = table.query(
IndexName='CustomerOrdersIndex',
KeyConditionExpression='customer_id = :cid AND date_status = :ds',
ExpressionAttributeValues={
':cid': 'C123',
':ds': sort_key
}
)
After:
# Clean and intuitive with multi-attribute GSI
response = table.query(
IndexName='CustomerOrdersIndex',
KeyConditionExpression='customer_id = :cid AND order_date = :date AND order_status = :status',
ExpressionAttributeValues={
':cid': 'C123',
':date': '2024-11-24',
':status': 'PENDING'
}
)
Pro Tips
-
Do Not Go Crazy: Just because you CAN add 8 fields does not mean you SHOULD. GSIs consume additional storage and throughput.
-
Watch Your Capacity: Each GSI needs its own read/write capacity units. Plan accordingly.
-
Eventually Consistent: Remember, GSIs are eventually consistent. The more fields, the longer it might take to sync.
-
Query Pattern Rules:
- All partition key attributes must use equality (=) conditions
- Range conditions (<, >, BETWEEN) only work on the last sort key attribute
- You can not skip sort keys - use them left-to-right (SK1, or SK1+SK2, or SK1+SK2+SK3)
-
Base Table vs GSI: Your base table’s primary key structure has not changed - this feature is exclusively for GSIs to give you more flexible query patterns!
The Bottom Line
This is one of those updates that makes you wonder, “How did we live without this?” If you have been dealing with concatenated fields or complex workarounds in your GSIs, it is time to refactor and simplify.
Your future self (and your teammates) will thank you.
Ready to try it? Head to your DynamoDB console and create a GSI with multiple attributes. It is available now in all AWS regions at no additional cost beyond standard GSI pricing!
Published on:
Learn moreWe can help you with DynamoDB Just Made Your Life Easier: Multi-Attribute Composite Keys Explained
If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.
Related posts
Vasanam Studio: How I Built a Bible Verse Video Generator for My Church as a Hobby Project
Every morning at 5 AM, the women of my church gather for prayer. At the end of the session, our pastor’s wife shares a Bible verse and sends a...
The demo worked. That was the problem.
Over a weekend I built a small Kubernetes demo to play with zero trust. Three little services calling each other in a chain, a login page in f...
Notes from building an agent on AgentCore end to end
I wanted a reason to use AgentCore end to end. Runtime, memory, guardrails, identity, the whole thing. A Bible Q&A agent felt like a good ...
Building a Rust gRPC AI Security Gateway for LLM Traffic
I wanted a small, honest implementation of the GenAI governance shape in code: a component on every LLM call that applies policy first, option...
Claude Code Security: The Smart Way to Integrate AI
Anthropic just dropped Claude Code Security, and if you’re anywhere near AppSec or DevSecOps, you’ve probably already seen the debate lighting...
How I Built a Semantic Cache Using Only AWS Services
LLM calls are expensive and slow, but here’s the thing - users ask the same questions in different ways all the time. “What’s your refund poli...
How to Build Better AI Agent Tools: Cut Costs by 70% (MCP Server Case Study)
Building tools for AI agents isn’t the same as building regular APIs. This guide shows you how to design tools that reduce token costs by 60-7...
Building a DevSecOps Pipeline on AWS (And You Can Too)
I have been working with CI/CD pipelines for a while now, and honestly, most of them just focus on getting code deployed fast. But what about ...
AWS DevOps Agent: AI-Powered Incident Investigation in Seconds
Stop spending 30 minutes investigating incidents. Let AI do it in seconds. Here is a hands-on demo you can practice in 15 minutes. The Proble...