AWS dynamodb 端点不正确
AWS dynamodb endpoints is not correct
我正在使用 sails js
(最新版本 1.0)和 DynamoDB(我已经在我的本地机器上安装了 Sails js 框架)但是当我试图从 aws dynamodb
读取记录时出现错误.我尝试了以下案例,每次都会遇到不同的错误。
var AWS = require("aws-sdk");
AWS.config.update({
region: "ap-southeast-2",
endpoint: "http://localhost:1337"
});
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "SMSGateway_User";
var email = 'yoursptc@gmail.com';
var params = {
TableName: table,
Key:{
"userEmail": email
}
};
docClient.get(params, function(err, data) {
if (err) {
console.log("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
我得到的错误:
Unable to read item. Error JSON: { "message": "Missing credentials
in config", "errno": "ETIMEDOUT", "code": "CredentialsError",
"syscall": "connect", "address": "169.254.169.254", "port": 80,
"time": "2018-10-05T05:05:26.002Z", "originalError": {
"message": "Could not load credentials from any providers",
"errno": "ETIMEDOUT",
"code": "CredentialsError",
"syscall": "connect",
"address": "169.254.169.254",
"port": 80,
"time": "2018-10-05T05:05:26.001Z",
"originalError": {
"errno": "ETIMEDOUT",
"code": "ETIMEDOUT",
"syscall": "connect",
"address": "169.254.169.254",
"port": 80,
"message": "connect ETIMEDOUT 169.254.169.254:80"
} } }
当我更改并为配置添加以下代码时:
AWS.config.update({
accessKeyId: 'XXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
region: "ap-southeast-2",
endpoint: "http://localhost:1337"
});
然后出现以下错误:
Unable to read item. Error JSON: { "message": "Not Found", "code":
"UnknownError", "statusCode": 404, "time":
"2018-10-05T06:08:28.707Z", "retryable": false, "retryDelay":
47.4917958614573 }
当我更改终点并输入 ARN
AWS.config.update({
accessKeyId: 'XXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
region: "ap-southeast-2",
endpoint: "arn:aws:dynamodb:ap-southeast-2:420344081058:table/SMSGateway_User"
});
错误是:
Unable to read item. Error JSON: { "message": "Inaccessible host:
arn'. This service may not be available in the
ap-southeast-2'
region.", "code": "UnknownEndpoint", "region": "ap-southeast-2",
"hostname": "arn", "retryable": true, "originalError": {
"message": "getaddrinfo ENOTFOUND arn arn:443",
"errno": "ENOTFOUND",
"code": "NetworkingError",
"syscall": "getaddrinfo",
"hostname": "arn",
"host": "arn",
"port": 443,
"region": "ap-southeast-2",
"retryable": true,
"time": "2018-10-05T06:17:21.352Z" }, "time": "2018-10-05T06:17:21.352Z" }
谁能告诉我在 dynamoDB 中读取、创建、更新和删除数据的正确终点是哪一个。
任何帮助将不胜感激。
经过大量研究,我找到了为什么它不起作用的解决方案
var AWS = require("aws-sdk");
//AWS.config.loadFromPath('details.json');
AWS.config.update({
accessKeyId: 'XXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
region: "XXXXXXXXX",
});
var docClient = new AWS.DynamoDB.DocumentClient();
/* Get single item */
var table = "TABLE NAME";
var msgId = 'PRIMARY KEY VALUE';
var params = {
TableName: table,
Key:{
'MsgId': msgId
}
};
docClient.get(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
要获取 table 的所有记录,只需使用如下所示的扫描功能
var table = "PadmanStopsTest";
var params = {
TableName: table,
};
docClient.scan(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
不需要终点,只需要通过accessKeyId
、secretAccessKey
和region
。我在参数中传递电子邮件,所以这里我们需要传递 table.
的主键值
我已经通过了,它对我来说工作正常。
我正在使用 sails js
(最新版本 1.0)和 DynamoDB(我已经在我的本地机器上安装了 Sails js 框架)但是当我试图从 aws dynamodb
读取记录时出现错误.我尝试了以下案例,每次都会遇到不同的错误。
var AWS = require("aws-sdk");
AWS.config.update({
region: "ap-southeast-2",
endpoint: "http://localhost:1337"
});
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "SMSGateway_User";
var email = 'yoursptc@gmail.com';
var params = {
TableName: table,
Key:{
"userEmail": email
}
};
docClient.get(params, function(err, data) {
if (err) {
console.log("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
我得到的错误:
Unable to read item. Error JSON: { "message": "Missing credentials in config", "errno": "ETIMEDOUT", "code": "CredentialsError",
"syscall": "connect", "address": "169.254.169.254", "port": 80,
"time": "2018-10-05T05:05:26.002Z", "originalError": { "message": "Could not load credentials from any providers", "errno": "ETIMEDOUT", "code": "CredentialsError", "syscall": "connect", "address": "169.254.169.254", "port": 80, "time": "2018-10-05T05:05:26.001Z", "originalError": { "errno": "ETIMEDOUT", "code": "ETIMEDOUT", "syscall": "connect", "address": "169.254.169.254", "port": 80, "message": "connect ETIMEDOUT 169.254.169.254:80" } } }
当我更改并为配置添加以下代码时:
AWS.config.update({
accessKeyId: 'XXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
region: "ap-southeast-2",
endpoint: "http://localhost:1337"
});
然后出现以下错误:
Unable to read item. Error JSON: { "message": "Not Found", "code": "UnknownError", "statusCode": 404, "time": "2018-10-05T06:08:28.707Z", "retryable": false, "retryDelay": 47.4917958614573 }
当我更改终点并输入 ARN
AWS.config.update({
accessKeyId: 'XXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
region: "ap-southeast-2",
endpoint: "arn:aws:dynamodb:ap-southeast-2:420344081058:table/SMSGateway_User"
});
错误是:
Unable to read item. Error JSON: { "message": "Inaccessible host:
arn'. This service may not be available in the
ap-southeast-2' region.", "code": "UnknownEndpoint", "region": "ap-southeast-2",
"hostname": "arn", "retryable": true, "originalError": { "message": "getaddrinfo ENOTFOUND arn arn:443", "errno": "ENOTFOUND", "code": "NetworkingError", "syscall": "getaddrinfo", "hostname": "arn", "host": "arn", "port": 443, "region": "ap-southeast-2", "retryable": true, "time": "2018-10-05T06:17:21.352Z" }, "time": "2018-10-05T06:17:21.352Z" }
谁能告诉我在 dynamoDB 中读取、创建、更新和删除数据的正确终点是哪一个。
任何帮助将不胜感激。
经过大量研究,我找到了为什么它不起作用的解决方案
var AWS = require("aws-sdk");
//AWS.config.loadFromPath('details.json');
AWS.config.update({
accessKeyId: 'XXXXXXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
region: "XXXXXXXXX",
});
var docClient = new AWS.DynamoDB.DocumentClient();
/* Get single item */
var table = "TABLE NAME";
var msgId = 'PRIMARY KEY VALUE';
var params = {
TableName: table,
Key:{
'MsgId': msgId
}
};
docClient.get(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
要获取 table 的所有记录,只需使用如下所示的扫描功能
var table = "PadmanStopsTest";
var params = {
TableName: table,
};
docClient.scan(params, function(err, data) {
if (err) {
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
}
});
不需要终点,只需要通过accessKeyId
、secretAccessKey
和region
。我在参数中传递电子邮件,所以这里我们需要传递 table.
我已经通过了,它对我来说工作正常。