Querying DynamoDB without Primary Key

Note:- As you have not provided the full code, it is difficult to simulate and identify the issue. However, I have created the similar tables and indexes. It works fine for me. You can refer the below code for more details.

Here is the table create script and query the index.

You can change the table name and index name if required. I have followed the same key attributes structure that you have mentioned on post.

This has been tested and working fine.

1) Create table 'city' with index 'city_index':-

var params = {
        TableName: 'city',
        KeySchema: [ // The type of of schema.  Must start with a HASH type, with an optional second RANGE.
            { // Required HASH type attribute
                AttributeName: 'id',
                KeyType: 'HASH',
            },
            { // Required HASH type attribute
                AttributeName: 'name',
                KeyType: 'RANGE',
            }            

        ],
        AttributeDefinitions: [ // The names and types of all primary and index key attributes only
            {
                AttributeName: 'id',
                AttributeType: 'S', // (S | N | B) for string, number, binary
            },
            {
                AttributeName: 'name',
                AttributeType: 'S', // (S | N | B) for string, number, binary
            },
            {
                AttributeName: 'city',
                AttributeType: 'S', // (S | N | B) for string, number, binary
            },

        ],
        ProvisionedThroughput: { // required provisioned throughput for the table
            ReadCapacityUnits: 400, 
            WriteCapacityUnits: 400, 
        },
        GlobalSecondaryIndexes: [ // optional (list of GlobalSecondaryIndex)
            { 
                IndexName: 'city_index', 
                KeySchema: [
                    { // Required HASH type attribute
                        AttributeName: 'city',
                        KeyType: 'HASH',
                    }
                ],
                Projection: { // attributes to project into the index
                    ProjectionType: 'ALL' // (ALL | KEYS_ONLY | INCLUDE)
                },
                ProvisionedThroughput: { // throughput to provision to the index
                    ReadCapacityUnits: 400,
                    WriteCapacityUnits: 400,
                },
            },
            // ... more global secondary indexes ...
        ],

    };
    dynamodb.createTable(params, function(err, data) {
        if (err){ console.log("error :" +JSON.stringify(err));} // an error occurred
        else console.log("success :" +JSON.stringify(data)); // successful response

    });

2) Insert some data to city table

3) Query using index:-

var docClient = new AWS.DynamoDB.DocumentClient();
var table = "city";
var params = {
    TableName : table,
    IndexName : 'city_index',
    KeyConditionExpression : 'city = :cityVal', 
    ExpressionAttributeValues : {
        ':cityVal' : 'london'        
    }
};

docClient.query(params, function(err, data) {
    if (err) {
        console.error("Unable to read item. Error JSON:", JSON.stringify(err,
                null, 2));
    } else {
        console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    }
});

This is my implementation with Node.js (of querying by another field) with scan:

  var params = {
    TableName: 'TableName',
    FilterExpression: 'AnotherFieldName = :email',
    ExpressionAttributeValues: {
      ":email": { S: emailISearchFor }  
    }
  };

  ddb.scan(params, function(err, data){
    if(err){
      ...
    } else {

      if(data.Items.length > 0){ // here is the info
        valueIWant = data.Items[0].PrimaryKeyName.S;
      }

    }

  });