【发布时间】:2019-11-14 08:20:47
【问题描述】:
我正在尝试实现一个基于 DynamoDB 的应用程序来存储一些请求数据。我阅读了DynamoDB官方文档,目前正在关注this官方教程做一些基本操作。
我正在使用本地 DynamoDB docker 容器。你可以这样运行它:
docker run -d -p 8000:8000 amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -sharedDb
当我尝试按照上面给出的教程创建一个新表时,我没有收到任何错误,一切都很好:
var params = {
TableName: 'book',
KeySchema: [
{
AttributeName: 'title',
KeyType: 'HASH',
}
],
AttributeDefinitions: [
{
AttributeName: 'title',
AttributeType: 'S'
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1,
}
};
dynamodb.createTable(params, function(err, data) {
if (err) print(err); // an error occurred
else print(data); // successful response
});
但是当我尝试在其中放入一些新项目时:
var params = {
TableName: 'book',
Item: { // a map of attribute name to AttributeValue
title: "Sample Application: CloudList",
chapter: 10
}
};
dynamodb.putItem(params, function(err, data) {
if (err) print(err); // an error occurred
else print(data); // successful response
});
我收到了这个错误:
31 验证错误实际上等于标题中的字符数:Sample Application: CloudList。 DynamoDB shell 也无法识别上述教程中给出的打印功能。所以我不得不用 ppJson 函数替换它。我在哪里做错了,如何通过 Web Shell 从 DynamoDB 放置/删除/获取项目? (也可以通过 PHP 代码)
编辑:我也尝试了 Vikdor 在评论中所说的,似乎我摆脱了 UnexpectedParameter 错误但这次我得到了 Invalid attribute value type 错误。
var params = {
TableName: 'book',
Item: { // a map of attribute name to AttributeValue
'title': {S: "Sample Application: CloudList"},
'chapter': {N: '10'}
}
};
【问题讨论】:
标签: javascript php database amazon-dynamodb