代码之家  ›  专栏  ›  技术社区  ›  Raghbendra Nayak

AWS dynamodb终结点不正确

  •  1
  • Raghbendra Nayak  · 技术社区  · 6 年前

    我正在使用 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));
        }
    });
    

    我得到的错误:

    无法读取项目。错误JSON:{“message”:“缺少凭据 在config中,“errno”:“ETIMEDOUT”,“code”:“credentialsrerror”,

    “时间”:“2018-10-05T05:05:26.002Z”,“原始错误”:{ “message”:“无法从任何提供商加载凭据”, “errno”:“ETIMEDOUT”, “code”:“凭证错误”, “syscall”:“连接”, “端口”:80, “errno”:“ETIMEDOUT”, “code”:“ETIMEDOUT”, “syscall”:“连接”, “端口”:80, “message”:“连接ETIMEDOUT 169.254.169.254:80” } } }

    AWS.config.update({
      accessKeyId: 'XXXXXXXXXXXX',
      secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
      region: "ap-southeast-2",
      endpoint: "http://localhost:1337"
    });
    

    然后得到以下错误:

    无法读取项目。错误JSON:{“message”:“找不到”,“code”: “未知错误”,“状态码”:404,“时间”: “2018-10-05T06:08:28.707Z”,“可重试”:假,“重试延迟”:

    当我改变终点,把阿恩

    AWS.config.update({
      accessKeyId: 'XXXXXXXXXXXX',
      secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
      region: "ap-southeast-2",
      endpoint: "arn:aws:dynamodb:ap-southeast-2:420344081058:table/SMSGateway_User"
    });
    

    错误是:

    arn'. This service may not be available in the ap-东南-2' 区域“,”代码“:”未知点“,”区域“:”ap-东南-2”,
    “hostname”:“arn”,“retryable”:true,“originalError”:{ “message”:“getaddrinfo ENOTFOUND arnarn:443", “code”:“网络错误”, “hostname”:“arn”, “端口”:443, “region”:“ap-东南-2”, “retryable”:正确, “时间”:“2018-10-05T06:17:21.352Z”},“时间”:“2018-10-05T06:17:21.352Z”}

    以下是我的参考资料: https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html#GettingStarted.NodeJs.03.02

    任何帮助都将不胜感激。

    1 回复  |  直到 6 年前
        1
  •  3
  •   Raghbendra Nayak    6 年前

    经过大量的研究,我找到了它为什么不起作用的答案

       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));
           }
       });
    

    要获取表的所有记录,只需使用下面的scan函数

       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 . 我在params中传递电子邮件,所以这里我们需要传递表的主键值。

    我通过了考试,对我来说很好。