我正在尝试与DynamoDB竞争Node js amazon启动指南。我正在尝试创建一个表,但这是我的错误:
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。它似乎工作正常。
感谢。
答案 0 :(得分:4)
您正在将AWS端点设置为http://localhost:8000
。这使得AWS SDK将AWS API调用发送到该URL而不是Amazon的服务器。你确定那是你想要的吗?除非您在本地运行DynamoDB版本,否则将针对每个DynamoDB请求向您自己的服务器发出请求,并尝试将结果解释为JSON。
SDK通常会根据区域正确设置端点,因此通常无需手动设置端点。尝试在没有端点设置的情况下配置AWS:
AWS.config.update({
region: "us-west-2"
});