Return subset of attribute value when reading item

Viewed 21

My dynamodb table is storing multiple attributes on each item, one of which being an array with a relatively large amount of entries. Whenever I read an item of my table, I really only need a certain subset of that array, so it's a waste of data throughput to query the entire thing.

Example: A good analogy would be stock price history; each entry in my table represents a certain stock, and the array attribute is the price history of the stock. When I query a stock, I will always know a start and end date (index of my array), which will usually be a very small subset of the entire array, so I'd optimally like to return my item with just that subset filled in the array attribute.

I guess a more standard way of doing this would be to use a relational database instead with a "prices" table, but that wouldn't fit that well with the rest of my model, while also ending up in being a table with an absolute humongous amount of entries.

Really, what I'm trying to do is just reduce the cost of my AWS calls.

1 Answers

Note: the question asks how to a return a subset of a single attribute value (which is unsupported in DynamoDB) rather than how to return a subset of available attributes (which is supported). I've answered the latter.

You haven't indicated which language SDK you are using, but all SDKs expose the DynamoDB GetItem API call and they all allow you to indicate which attributes you want returned to you in ProjectionExpression or the legacy AttributesToGet.

An example ProjectionExpression is "Artist, Genre" for the two named attributes.

Related