在具有dynalite的Vogels上,未找到请求的资源

时间:2017-02-10 20:33:54

标签: javascript amazon-dynamodb aws-sdk vogels dynalite

有人可以分享有关如何vogels dynalite工作的信息吗?

以下是我在计算机上本地实例化数据库服务器的方法:

import dynalite from 'dynalite';
import packageJSON from '../package.json'

// Returns a standard Node.js HTTP server
const dynaliteServer = dynalite({ path: '../mydb', createTableMs: 50 })

dynaliteServer.listen(packageJSON.config.endpointPort, function (err) {
    if (err) throw err
    console.log('Dynalite started on port ' + packageJSON.config.endpointPort);
});

以下是我尝试初始化vogels的内容:

import packageJSON from '../package.json';
import AWS from 'aws-sdk';
import vogels from 'vogels';

export default function initContext() {
  const AWSConfig = {
    accessKeyId: packageJSON.config.KEY,
    secretAccessKey: packageJSON.config.SECRET,
    region: packageJSON.config.region,
    endpoint: packageJSON.config.endpoint
  };

  //config AWD
  AWS.config.update(AWSConfig);

  //create dynamodb instance
  const dynamodb = new AWS.DynamoDB(AWSConfig);

  //config vogels AWS
  vogels.AWS.config.update(AWSConfig);
  vogels.dynamoDriver(dynamodb);

  return {
    dynamodb,
    vogels
  };
}

我已经定义了一个模型并尝试在名为initDB.js的文件中创建它:

initContext();

myVogelsModel.create({
    name: 'foo',
    email: 'foo@example.com',
}, function (err, model) {
    console.log(err);
});

但它只返回了我的错误:

{ [ResourceNotFoundException: Requested resource not found]
  message: 'Requested resource not found',
  code: 'ResourceNotFoundException',
  time: Thu Feb 09 2017 22:53:46 GMT+0100 (Paris, Madrid),
  requestId: 'CATZQFWSMVJKOLP0YTIMU9IEVSLJBVAB7NJB8L3EIHXCDXLT30AQ',
  statusCode: 400,
  retryable: false,
  retryDelay: 0 }
C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\request.js:31
            throw err;
            ^

TypeError: Cannot read property 'get' of undefined
    at C:/Users/damien/Documents/workspace/myProject/src/initDB.js:23:34
    at C:\Users\damien\Documents\workspace\myProject\node_modules\vogels\lib\table.js:193:16
    at Response.<anonymous> (C:\Users\damien\Documents\workspace\myProject\node_modules\vogels\lib\table.js:69:14)
    at Request.<anonymous> (C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\request.js:355:18)
    at Request.callListeners (C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
    at Request.emit (C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
    at Request.emit (C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\request.js:668:14)
    at Request.transition (C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\request.js:22:10)
    at AcceptorStateMachine.runTo (C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\state_machine.js:14:12)
    at C:\Users\damien\Documents\workspace\myProject\node_modules\aws-sdk\lib\state_machine.js:26:10

任何提示都将不胜感激:)

1 个答案:

答案 0 :(得分:1)

问题已解决。

问题似乎是我用一个定义为Number的键创建了表(使用aws-sdk-js dynamodb.createTable函数),而我的Vogels模型的键是UUID(又名string

当尝试使用vogels在表中添加项时:它不起作用:因为使用命令aws dynamodb list-tables --endpoint-url http://localhost:4567而感到困惑:我得到了正确的表列表。

所以我尝试使用函数vogels vogels.createTables创建表。之后,调用myVogelsModel.create函数完全正常。

FI:The topic on github