我有一个本地 dynamo-db 正在运行。我已经使用 JavaScript 控制台设置了我的表,它们从那里列出了 OK。
我还可以从 JavaScript 控制台向我的表中放置和获取项目:
var params = { TableName:"environmentId", Item: { environmentId: {"S":"a4fe1736-98cf-4560-bcf4-cc927730dd1b"} }};
dynamodb.putItem(params, function(err, data) {
console.log("put : err was " + JSON.stringify(err) + " and data is " + JSON.stringify(data));
});
put : err was null and data is {}
我假设的打印是“成功”的,因为
params = { "Key":{"environmentId":{"S":"a4fe1736-98cf-45e0-bcf4-cc927730dd1b"}},"TableName":"environmentId"}
dynamodb.getItem(params, function(err, data) {
console.log("get : err was " + JSON.stringify(err) + " and data is " + JSON.stringify(data));
});
打印get : err was null and data is {"Item":{"environmentId":{"S":"a4fe1736-98cf-45e0-bcf4-cc927730dd1b"}}}
,即它检索我刚刚放到表中的对象。
但是,如果它启动节点 REPL 并输入:
var AWS = require('aws-sdk');
AWS.config.loadFromPath("./config/credentials.js");
endpoint = new AWS.Endpoint("http://localhost:8000");
var dynamoOpts = {apiVersion: '2012-08-10', 'endpoint':endpoint};
var dynamodb = new AWS.DynamoDB(dynamoOpts);
var params = { TableName:"environmentId", Item: { environmentId: {"S":"a4fe1736-98cf-4560-bcf4-cc927730dd1b"} }};
dynamodb.putItem(params, function(err, data) {
console.log("put : err was " + JSON.stringify(err) + " and data is " + JSON.stringify(data));
}
我收到资源未找到错误:
{ "message":"Cannot do operations on a non-existent table",
"code":"ResourceNotFoundException",
"time":"2015-04 10T10:01:26.319Z",
"statusCode":400,
"retryable":false,
"retryDelay":0
}
从 putCommand 返回的 ASW.request 对象具有正确的端点:
{ protocol: 'http:',
host: 'localhost:8000',
port: 8000,
hostname: 'localhost',
pathname: '/',
// etc.
我的 Node 应用程序也发生了同样的事情,但是连接到真正的 AWS 托管发电机的相同代码可以工作。