Configuring maxSockets in Node.js - AWS SDK for JavaScript

Help us improve the AWS SDK for JavaScript version 3 (V3) documentation by providing feedback using the Feedback link, or create an issue or pull request on GitHub.

The AWS SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the AWS 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.

const { DynamoDBClient } = require("@aws-sdk/client-dynamodb"); const { NodeHttpHandler } = require("@aws-sdk/node-http-handler"); var https = require("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.