deleteItem - 提供的关键元素与架构不匹配 (Node.js)
deleteItem - The provided key element does not match the schema (Node.js)
我正在尝试使用具有反向代理集成和 lambda 的 http api 网关删除 dynamodb 上的项目。这是它在日志上所说的:
"message": "The provided key element does not match the schema",
"code": "ValidationException",
"statusCode": 400
这是我的架构:
我正在尝试在我的 lambda 中删除 hello
:
let PK = event.queryStringParameters.PK
const params = {
Key: {
"PK": {
S: PK
}
},
TableName: "myTableX"
};
dynamodb.deleteItem(params, function(err, data) {
if (err) {
console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
} else {
callback(null, {
"statusCode": 200,
"body": "Deleted successfully"
});
}
});
知道我做错了什么吗?
目前,您不能仅通过传递 Hash 键来删除所有项目,要删除一个项目,它需要 Hash + Range,因为这就是它的唯一性。
这是来自 DynamoDB 文档的参考 link http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html#API_DeleteItem_RequestSyntax
For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.
这意味着您必须为查询提供 PK
和 SK
值,例如:
const params = {
Key: {
"PK": {
S: PK
},
"SK": {
S: "SK value", // this value
}
},
TableName: "myTableX"
};
我正在尝试使用具有反向代理集成和 lambda 的 http api 网关删除 dynamodb 上的项目。这是它在日志上所说的:
"message": "The provided key element does not match the schema",
"code": "ValidationException",
"statusCode": 400
这是我的架构:
我正在尝试在我的 lambda 中删除 hello
:
let PK = event.queryStringParameters.PK
const params = {
Key: {
"PK": {
S: PK
}
},
TableName: "myTableX"
};
dynamodb.deleteItem(params, function(err, data) {
if (err) {
console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
} else {
callback(null, {
"statusCode": 200,
"body": "Deleted successfully"
});
}
});
知道我做错了什么吗?
目前,您不能仅通过传递 Hash 键来删除所有项目,要删除一个项目,它需要 Hash + Range,因为这就是它的唯一性。
这是来自 DynamoDB 文档的参考 link http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html#API_DeleteItem_RequestSyntax
For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.
这意味着您必须为查询提供 PK
和 SK
值,例如:
const params = {
Key: {
"PK": {
S: PK
},
"SK": {
S: "SK value", // this value
}
},
TableName: "myTableX"
};