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!

dynamodb-multi-attribute-2

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

dynamodb-multi-attribute-1

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

  1. Do Not Go Crazy: Just because you CAN add 8 fields does not mean you SHOULD. GSIs consume additional storage and throughput.

  2. Watch Your Capacity: Each GSI needs its own read/write capacity units. Plan accordingly.

  3. Eventually Consistent: Remember, GSIs are eventually consistent. The more fields, the longer it might take to sync.

  4. 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)
  5. 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!