首页 > 解决方案 > AWS Dynamodb 配置中缺少凭证,如果使用 AWS_CONFIG_FILE,则设置 AWS_SDK_LOAD_CONFIG=1

问题描述

我正在尝试在dynamodb表中添加元素,如下例所示,但是当我运行它时,我收到以下错误消息:Missing credentials in the config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

aws.config.update({
   region: "eu-west-1",
   endpoint: "http://localhost:8080",})


  let ddb = new aws.DynamoDB.DocumentClient({
    apiVersion: "2012-08-10",
  });

  let params = {
    TableName: "NameOfTheTable",
    Item: {
      uuid: JSON.stringify(132), // random number for testing
      name: JSON.stringify(req.query.mod), //data i'm passing in
    },
  };

const addMod = ddb.put(params, function (err, data) {
  if (err) {
    console.log("Error", err);
  } else {
    console.log("Success", data);
  }
});
return res.send(addMod);

});

我想可能我错过了accessKeyIdaccessSecretKey但老实说,我不明白如何设置它们

标签: javascriptnode.jsdatabaseamazon-web-servicesamazon-dynamodb

解决方案


您似乎在查询本地凭据,因为 SDK 会检查它们,这似乎是一个问题

您可以通过指定任何字符串来解决。试试下面的代码片段。

aws.config.update({
    region: "eu-west-1",
    endpoint: "http://localhost:8080",
    accessKeyId: “xxxxxx”,
    secretAccessKey: “xxxxxx”
});

推荐阅读