2

当我将应用程序部署到 AWS 时,我遇到了严重的 aws-sdk 性能问题。我正在使用它,如下所示:

wrapper = {
    accessKeyId: "YOURACCESSKEY",
    secretAccessKey: "YOURSECRETKEY",
    region: "us-east-1",
    endpoint: new AWS.Endpoint('http://localhost:8000')
};

AWS.config.update(wrapper);

const docClient = new AWS.DynamoDB.DocumentClient();

module.exports ={"docClient":docClient};

我研究并发现 - https://github.com/aws/aws-sdk-js/issues/900 - 我们可以在 aws 中指定 httpOptions 以便启用 keepAlive。

我的问题是,如何在上面的 AWS-sdk 构造函数中指定 httpOptions:

var dynamo = new AWS.DynamoDB({
  region: "ap-southeast-2",
  httpOptions: {
  agent: new https.Agent({
  rejectUnauthorized: true,
  keepAlive: true
  })
}

});

如何将其添加到包装器配置中。它不接受 AWS.config.update 中任何额外的 httpOptions 键

4

1 回答 1

6

应该是这样的。。

new AWS.DynamoDB.DocumentClient({
    service: new AWS.DynamoDB({
      region: "ap-southeast-2",
      httpOptions: {
        agent: new Https.Agent({ keepAlive: true })
      }
    })
  })

它必须添加到 DocumentClient,而不是 DynamoDB 本身。

于 2018-02-12T01:11:31.667 回答