Reusing connections with keep-alive in Node.js - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

The Amazon SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the Amazon SDK for JavaScript version 3 (V3).

Starting October 1, 2022, Amazon SDK for JavaScript (v3) will end support for Internet Explorer 11 (IE 11). For details, see Announcing the end of support for Internet Explorer 11 in the Amazon SDK for JavaScript (v3).

Reusing connections with keep-alive in Node.js

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, the SDK for JavaScript reuses TCP connections.

For short-lived operations, such as Amazon DynamoDB queries, the latency overhead of setting up a TCP connection might be greater than the operation itself. Additionally, since DynamoDB encryption at rest is integrated with Amazon KMS, you may experience latencies from the database having to re-establish new Amazon KMS cache entries for each operation.

To disable reusing TCP connections, set the AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable to false (the default is true).

You can also disable keeping these connections alive on a per-service client basis, as shown in the following example for a DynamoDB client.

import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { NodeHttpHandler } from "@aws-sdk/node-http-handler"; import { Agent } from "http"; const dynamodbClient = new DynamoDBClient({ requestHandler: new NodeHttpHandler({ httpAgent: new Agent({keepAlive: false}) }) });

If keepAlive is enabled, you can also set the initial delay for TCP Keep-Alive packets with keepAliveMsecs, which by default is 1000 ms. See the Node.js documentation for details.