I'm terribly confused by something in DynamoDB:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForLSI.html#GuidelinesForLSI.SparseIndexes
For any item in a table, DynamoDB will only write a corresponding index entry if the index sort key value is present in the item. If the sort key does not appear in every table item, the index is said to be sparse.
[...]
To track open orders, you can create an index on CustomerId (partition key) and IsOpen (sort key). Only those orders in the table with IsOpen defined will appear in the index.
But if you have an LSI defined with an alternate sort key, when you create new items, that alternate sort key can never be null. So therefore the index isn't sparse at all because every item I create will wind up in the index.
What am I missing?
So I finally figured it out. I should've clarified I was using the AWS console.
I created a GSI as a test, with partition key Gpart
and sort key Gsort
. I noticed when I create a new item, these fields are added automatically, and I cannot leave them blank, which is where I was getting stuck. (I'd get the error "One or more parameter values were invalid: An AttributeValue may not contain an empty string")
Turns out, all I needed to do was actually just remove those fields.
After removing any GSI or LSI related attributes, I can save the item, and sure enough, those indexes only show items where those keys exist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With