I'm trying to do this query in the local DynamoDB but I don't know why it doesn't work
Error:
Unable to read item. Error JSON: { "message": "Query condition missed key schema element", "code": "ValidationException", "time": "2020-04-13T23:49:24.297Z", "requestId": "99bcabdb-7168-4b26-8056-74482d92ac42", "statusCode": 400, "retryable": false, "retryDelay": 23.68974772992818 }
Query
var params = {
TableName: TESTE,
IndexName: 'indexCNPJ',
KeyConditionExpression: 'cep = :cep',
ExpressionAttributeValues: {
':cep': cep
}
};
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));
res.status(200).json(data)
}
}); ```
**Table**
``` var params = {
TableName : "TESTE",
KeySchema: [
{ AttributeName: "CEP", KeyType: "HASH"},
{ AttributeName: "CNPJ", KeyType: "RANGE"}
],
AttributeDefinitions: [
{ AttributeName: "CEP", AttributeType: "N" },
{ AttributeName: "CNPJ", AttributeType: "S" }
],
GlobalSecondaryIndexes: [
{
IndexName: 'indexCNPJ',
KeySchema: [
{ AttributeName: 'CEP', KeyType: 'HASH' },
{ AttributeName: 'CNPJ', KeyType: 'RANGE' }
],
Projection: {
ProjectionType: 'ALL'
},
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 10,
WriteCapacityUnits: 10
}
};
dynamodb.createTable(params, function(err, data) {
if (err) {
console.error("Unable to create table. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Created table. Table description JSON:", JSON.stringify(data, null, 2));
}
});
The only thing i wanted was just that when calling the service just pass the zip parameter. Because, it is not possible to create the table only with the zip code as HASH is that in the records there are duplicates
At first I only have the cep parameter. Does anyone know how I can solve this problem?