title: DynamoDB: Query on GSI (Global secondary index) does not return data
body: <p>I am using the Serverless framework to setup the below table:</p>
  
  <pre><code>provider:
    name: aws
    runtime: nodejs6.10
    stage: dev
    region: ap-southeast-1
    environment:
      DYNAMODB_TABLE: "Itinerary-${self:provider.stage}"
      DYNAMODB_COUNTRY_INDEX: country_index
    iamRoleStatements:
      - Effect: Allow
        Action:
          - dynamodb:Query
          - dynamodb:Scan
          - dynamodb:GetItem
          - dynamodb:PutItem
          - dynamodb:UpdateItem
          - dynamodb:DeleteItem
        Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
      - Effect: Allow
        Action:
          - dynamodb:Query
          - dynamodb:Scan
          - dynamodb:GetItem
          - dynamodb:PutItem
          - dynamodb:UpdateItem
          - dynamodb:DeleteItem
        Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}/index/${self:provider.environment.DYNAMODB_COUNTRY_INDEX}"
  resources:
    Resources:
      ItineraryTable:
        Type: 'AWS::DynamoDB::Table'
        DeletionPolicy: Retain
        Properties:
          AttributeDefinitions:
            -
              AttributeName: ID
              AttributeType: S
            -
              AttributeName: Country
              AttributeType: S
          KeySchema:
            -
              AttributeName: ID
              KeyType: HASH
          GlobalSecondaryIndexes:
            -
              IndexName: ${self:provider.environment.DYNAMODB_COUNTRY_INDEX}
              KeySchema:
                -
                  AttributeName: Country
                  KeyType: HASH
              Projection:
                ProjectionType: ALL
              ProvisionedThroughput:
                ReadCapacityUnits: 1
                WriteCapacityUnits: 1
          ProvisionedThroughput:
            ReadCapacityUnits: 1
            WriteCapacityUnits: 1
          TableName: ${self:provider.environment.DYNAMODB_TABLE}
  </code></pre>
  
  <p>Now, I am able to get to do a "get" to retrieve items from the DB by ID. However, if I try to do a "query" on the GSI, it returns nothing. There is no failure, but I never get data back.</p>
  
  <p>The below is what my query looks like:</p>
  
  <pre><code>const dynamoDb = new AWS.DynamoDB.DocumentClient();
  
  var params = {
      TableName: process.env.DYNAMODB_TABLE, // maps back to the serverless config variable above
      IndexName: process.env.DYNAMODB_COUNTRY_INDEX, // maps back to the serverless config variable above
      KeyConditionExpression: "Country=:con",
      ExpressionAttributeValues: { ":con" : "Portugal" }
  };
  
  dynamoDb.query(params, (error, result) =&gt; {
      // handle potential errors
      if (error) {
          console.error(error);
          callback(null, {
              statusCode: error.statusCode || 501,
              headers: { 'Content-Type': 'text/plain' },
              body: 'Couldn\'t fetch the Itineraries'+error,
          });
          return;
      }
  }
  
  var json_result = JSON.stringify(result.Item);
  </code></pre>
  
  <p>I should add here that I can't get data if I do a filterless "scan" as well. If I try to search for items by index (or otherwise) on the AWS Dynamo web portal, I get results though.</p>
  
  <p>I cannot figure out what it is that's going wrong here. Any light that someone can shed would be much appreciated.</p>