title: How can I Use begins_with method on primary key in DynamoDB?
body: <p>I have Table with 2 attribute id(string,primary key), value(string).
  When I try follwoing KeyConditionExpression it throws <strong>Query key condition not supported</strong>.</p>
  
  <pre><code>KeyConditionExpression: "begins_with(ID, :tagIDValue)" 
                          or
  KeyConditionExpression: "contains(ID, :tagIDValue)"
  </code></pre>
  
  <p>From <a href="https://forums.aws.amazon.com/thread.jspa?threadID=231708" rel="noreferrer">this</a> link I came to know we can use only EQ operations on main key. How can I achieve this</p>
  
  <p><strong>Solution:======================================================</strong></p>
  
  <p>I need to use begins_with or contains to filter So I went with following approach.</p>
  
  <p>Table attributes: PK(partion_key, string), ID(sort key, string), value(string).</p>
  
  <p>Now my primary key is framed based on PK,ID</p>
  
  <p>PK will have constant value for all rows. so KeyConditionExpression will be like.</p>
  
  <pre><code>KeyConditionExpression: "PL = :pk  and begins_with(ID, :tagIDValue)"
  </code></pre>
  
  <p><strong>NOTE: But still <em>contains</em> not working with KeyConditionExpression. I think it was removed from KeyConditionExpression</strong></p>