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

Configuring 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"; var agent = new https.Agent({ maxSockets: 25 }); var dynamodbClient = new DynamoDBClient({ requestHandler: new NodeHttpHandler({ httpsAgent: agent }) });

When using the default of https, the SDK takes the maxSockets value from the globalAgent. If the maxSockets value is not defined, the SDK assumes a maxSockets value of 50.

For more information about setting maxSockets in Node.js, see the Node.js online documentation.