title: AWS DynamoDB v2: Do I need secondary index for alternative queries?
body: <p>I need to create a table that would contain a slice of data produced by a continuously running process. This process generates messages that contain two mandatory components, among other things: a globally unique message UUID, and a message timestamp.</p>
  
  <p>Those messages would be later retrieved by the UUID.</p>
  
  <p>In addition, on a regular basis I would need to delete all messages from that table that are too old, i.e. whose timestamps are more than X away from the current time. </p>
  
  <p>I've been reading the DynamoDB v2 documentation (e.g. <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html" rel="nofollow">Local Secondary Indexes</a>) trying to figure out <strong>how to organize my table and whether or not I need a secondary index to perform searches for messages to delete</strong>. There might be a simple answer to my question, but I am somehow confused...</p>
  
  <p>So should I just create a table with the UUID as the hash and messageTimestamp as the range key (together with a "message" attribute that would contain the actual message), and then not create any secondary indices? In the examples that I've seen, the hash was something that was not unique (e.g. ForumName under the above link). In my case, the hash would be unique. I am not sure whether than makes any difference. </p>
  
  <p>And if I create the table with hash and range as described, and without a secondary index, then how would I query for all messages that are in a certain timerange regardless of their UUIDs?</p>