DynamoDB和Node Js:意外的令牌h

我试图与DynamoDB竞争Node js亚马逊入门指南。 我试图创build一个表,但这里是我的错误:

Unable to create table. Error JSON: { "message": "Unexpected token h", "code": "SyntaxError", "time": "2016-05-06T16:59:50.411Z", "statusCode": 200, "retryable": false, "retryDelay": 0 

我正在运行以下节点(直接从亚马逊开始指南):

 var AWS = require("aws-sdk"); AWS.config.loadFromPath('./.aws/credentials.json'); AWS.config.update({ region: "us-west-2", endpoint: "http://localhost:8000" }); var dynamodb = new AWS.DynamoDB(); var params = { TableName : "Movies", KeySchema: [ { AttributeName: "year", KeyType: "HASH"}, //Partition key { AttributeName: "title", KeyType: "RANGE" } //Sort key ], AttributeDefinitions: [ { AttributeName: "year", AttributeType: "N" }, { AttributeName: "title", AttributeType: "S" } ], 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)); } }); 

我在本教程的基础上,在端口8080上运行本地Web服务器: https : //www.youtube.com/watch?v=pU9Q6oiQNd0 。 它似乎工作正常。

谢谢。

您正在将AWS端点设置为http://localhost:8000 。 这使得AWS开发工具包将AWS API调用发送到该URL,而不是Amazon的服务器。 你确定这就是你想要的吗? 除非您在本地运行DynamoDB版本,否则会向您自己的服务器请求每个DynamoDB请求,并尝试将结果解释为JSON。

SDK通常会根据地区正确设置端点,所以通常不需要手动设置。 尝试configurationAWS而不使用端点设置:

 AWS.config.update({ region: "us-west-2" });