I have an AWS DynamoDb table,
I have user_id as an Index or GSI(user_id-index
),
And I have product_type also as an Index or GSI(prod_type-index
).
I am trying to use KeyConditionExpression to query the DynamoDb table,
But I am getting a -
Validation Exception, with message:"Query key condition not supported" and statusCode: 400
ValidationException: Query key condition not supported\n at Request.extractError
I have the following Item structure on the table -
{
"id": "12345f9f-f08c-45ae-986a-f1b5ac712345",
"user_id": 1234,
"prod_type": "OTHER"
}
Following is my NodeJs code for Querying the table -
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);
}
});
References -
Dynamodb query error - Query key condition not supported
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LegacyConditionalParameters.KeyConditions.html