在 Node 本地使用 dynamodb 时“无法从任何提供者加载凭据”

2024-01-06

我正在本地设置 dynamodb 以使用我的 Node 应用程序进行测试。为了设置它,我只是简单地复制了代码here http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.NodeJs.01.html并根据我的需要进行调整。
这是代码:

var AWS = require("aws-sdk");

var config = ({
  "apiVersion": "2012-08-10",
  "accessKeyId": "abcde",
  "secretAccessKey": "abcde",
  "region": "us-west-2",
  "endpoint": "http://localhost:8001",
});

var dynamodb = new AWS.DynamoDB(config);

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

但这会引发错误,我不知道为什么:

Unable to create table. Error JSON: {
  "message": "Missing credentials in config",
  "code": "CredentialsError",
  "time": "2017-04-10T11:45:26.748Z",
  "retryable": true,
  "originalError": {
    "message": "Could not load credentials from any providers",
    "code": "CredentialsError",
    "time": "2017-04-10T11:45:26.747Z",
    "retryable": true,
    "originalError": {
      "message": "Connection timed out after 1000ms",
      "code": "TimeoutError",
      "time": "2017-04-10T11:45:26.747Z",
      "retryable": true
    }
  }
}

将不胜感激任何帮助!


我有同样的错误。就我而言,问题是它在本地从命令行运行得很好,但在 docker 中却不行。

基本上如何将凭证传递给 AWS npm S3 客户端aws-sdk(版本 2)和@aws-sdk/s3-client(版本 3)已更改。在 v2 的情况下,结构是这样的:

const credentials = {
    region: configuration.aws.region,
    accessKeyId: configuration.aws.accessKeyId,
    secretAccessKey: configuration.aws.secretAccessKey
};

In v3:

const credentials = {
  region: configuration.aws.region,
  credentials: {
    accessKeyId: configuration.aws.accessKeyId,
    secretAccessKey: configuration.aws.secretAccessKey
  }
};

它在本地运行良好,因为我已经通过 CLI 向 AWS 进行了身份验证,并且它忽略了我传递给 v3 客户端的那些 v2 样式凭证。

结论:男孩和女孩的一切都使用 Typescript!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Node 本地使用 dynamodb 时“无法从任何提供者加载凭据” 的相关文章

随机推荐