title: How to query AWS DynamoDb using KeyConditionExpression?
body: <p>I have an AWS DynamoDb table,<br>
  I have user_id as an Index or GSI(user_id-index
  ),<br>
  And I have product_type also as an Index or GSI(prod_type-index
  ).<br></p>
  
  <p>I am trying to use KeyConditionExpression to query the DynamoDb table,<br>
  But I am getting a -</p>
  
  <pre><code>Validation Exception, with message:"Query key condition not supported" and statusCode: 400
  ValidationException: Query key condition not supported\n at Request.extractError 
  </code></pre>
  
  <p><strong>I have the following Item structure on the table -</strong><br></p>
  
  <pre><code>{
    "id": "12345f9f-f08c-45ae-986a-f1b5ac712345",
    "user_id": 1234,
    "prod_type": "OTHER"
  }
  </code></pre>
  
  <p><strong>Following is my NodeJs code for Querying the table -</strong><br></p>
  
  <pre><code>let AWS = require('aws-sdk');
  
  AWS.config.update({
      region: 'us-east-1'
  });
  
  let connection = new AWS.DynamoDB.DocumentClient();
  
  let table = "some_table";
  
  let params = {
      IndexName : "user_id-index",
      ExpressionAttributeValues: {
          ":v1": {
              N: 1234
          },
          ":v2": {
              S: "OTHER"
          }
      },
      ExpressionAttributeNames: {
          "#userId": "user_id",
          "#prodType": "prod_type"
      },
      TableName: table,
      KeyConditionExpression: "#userId = :v1 and #prodType = :v2"
  };
  
  connection.query(params, function(err, data) {
      if (err) {
          console.log(err);
      } else {
          console.log(data);
      }
  });
  </code></pre>
  
  <p><strong>References -</strong><br>
  <a href="https://stackoverflow.com/questions/31830888/dynamodb-query-error-query-key-condition-not-supported">Dynamodb query error - Query key condition not supported</a><br>
  <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.KeyConditions.html" rel="noreferrer">https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.KeyConditions.html</a></p>