title: Query dynamodb table by primary key
body: <p>I'm having problems creating a simple query request. <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#query-property" rel="nofollow noreferrer">Here</a> they show an example of how to do a query using the global secondary index. Now in this case, I just have the primary key, and I'd like to query from my table. This is currently the error that I'm getting: </p>
  
  <p><code>Query condition missed key schema element: id</code></p>
  
  <p>Here is what I'm currently trying:</p>
  
  <pre><code>var params = {
    TableName : "XactRemodel-7743-DynamoDBImagesTable-8183NQ0UG0Y5",
    KeyConditionExpression: 'HashKey = :hkey',
    ExpressionAttributeValues: {
      ':hkey': event.projectId
    }
  };
  documentClient.query(params, function(err, data) {
     if (err) {
       console.log(err)
     } else {
       console.log(data);
     }
  });
  </code></pre>
  
  <p>I know that in the example they used "indexName" which corresponds to the secondary indexes name. They Key Schema doesn't seem to have such an <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-keyschema.html" rel="nofollow noreferrer">attribute</a>.</p>
  
  <p>This is what my table looks like defined in a YAML file:</p>
  
  <pre><code>DynamoDBImagesTable:
  Type: AWS::DynamoDB::Table
  Properties:
    BillingMode: PAY_PER_REQUEST
    SSESpecification:
      SSEEnabled: true
    PointInTimeRecoverySpecification:
      PointInTimeRecoveryEnabled: true
    AttributeDefinitions:
      - AttributeName: id
        AttributeType: S
      - AttributeName: companyId
        AttributeType: S
      - AttributeName: lastModified
        AttributeType: S
    KeySchema:
      - AttributeName: id
        KeyType: HASH
    GlobalSecondaryIndexes:
      - IndexName: companyId-index
        KeySchema:
          - AttributeName: companyId
            KeyType: HASH
          - AttributeName: lastModified
            KeyType: RANGE
        Projection:
          ProjectionType: ALL
  </code></pre>
  
  <p>What am I missing? </p>