我的 DynamoDb 连接是否每次都关闭?

Does my DynamoDb connection Close every time?

我试图了解我的 Dynamodb 连接是否在我每次执行命令时关闭

const dboperation1 = async(param) =>{
    const docClient = new AWS.DynamoDB.DocumentClient();
    const result = await docClient.query(params).promise();
    return result

}

考虑到上面的例子,每次我调用 dboperation1 是否会导致首先建立与 DynamoDb 的连接。

如果是这样,我怎样才能让一些连接保持打开状态,以便我可以随时使用它们来查询数据库,避免花费额外的时间来建立连接?基本上是试图避免发生的初始握手。

来自文档:

By default, the default Node.js HTTP/HTTPS agent creates a new TCP connection for every new request. To avoid the cost of establishing a new connection, you can reuse an existing connection.

所有 AWS 开发工具包调用都使用 http(s) 连接。我们只需要构建一个 keepAlive 代理,并在初始化客户端时将其传递给 httpOptions。 这适用于所有其他 AWS SDK 客户端,而不仅仅是 DynamoDB。

const agent = new https.Agent({
  keepAlive: true
});

Here 是文档

下面是一个例子

import { Agent as httpsAgent } from 'https';
import AWS from 'aws-sdk';
var docClient = new DB.DocumentClient({
    httpOptions: {
        connectTimeout: 4000,
        agent: new httpsAgent({ keepAlive: true }),
    },
    logger: console,
    apiVersion: '2012-08-10',
    convertEmptyValues: true,
});