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

We announced the upcoming end-of-support for Amazon SDK for JavaScript v2. We recommend that you migrate to Amazon SDK for JavaScript v3. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

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 all service objects you create. This example allows up to 25 concurrent connections to each service endpoint.

var AWS = require('aws-sdk'); var https = require('https'); var agent = new https.Agent({ maxSockets: 25 }); AWS.config.update({ httpOptions:{ agent: agent } });

The same can be done per service.

var AWS = require('aws-sdk'); var https = require('https'); var agent = new https.Agent({ maxSockets: 25 }); var dynamodb = new AWS.DynamoDB({ apiVersion: '2012-08-10' httpOptions:{ agent: agent } });

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

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