Configure maxSockets 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 (PDF).

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).

Configure maxSockets in Node.js

In Node.js, you can set the maximum number of connections per origin. If maxSockets is set, the low-level HTTP client queues requests and assigns them to sockets as they become available.

This lets you set an upper bound on the number of concurrent requests to a given origin at a time. Lowering this value can reduce the number of throttling or timeout errors received. However, it can also increase memory usage because requests are queued until a socket becomes available.

The following example shows how to set maxSockets for a DynamoDB client.

import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { NodeHttpHandler } from "@smithy/node-http-handler"; import https from "https"; let agent = new https.Agent({ maxSockets: 25 }); let dynamodbClient = new DynamoDBClient({ requestHandler: new NodeHttpHandler({ requestTimeout: 3_000, httpsAgent: agent }); });

The SDK for JavaScript uses a maxSockets value of 50 if you do not supply a value or an Agent object. If you supply an Agent object, its maxSockets value will be used. For more information about setting maxSockets in Node.js, see the Node.js documentation.

As of v3.521.0 of the Amazon SDK for JavaScript, you can use the following shorthand syntax to configure requestHandler.

import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; const client = new DynamoDBClient({ requestHandler: { requestTimeout: 3_000, httpsAgent: { maxSockets: 25 }, }, });