Amazon QLDB driver for Node.js
Important
End of support notice: Existing customers will be able to use Amazon QLDB until end of support on 07/31/2025. For more details, see
Migrate an Amazon QLDB Ledger to Amazon Aurora PostgreSQL
To work with data in your ledger, you can connect to Amazon QLDB from your Node.js application by using an AWS provided driver. The following topics describe how to get started with the QLDB driver for Node.js.
Topics
Driver resources
For more information about the functionality supported by the Node.js driver, see the following resources:
Prerequisites
Before you get started with the QLDB driver for Node.js, you must do the following:
-
Follow the AWS setup instructions in Accessing Amazon QLDB. This includes the following:
-
Sign up for AWS.
-
Create a user with the appropriate QLDB permissions.
-
Grant programmatic access for development.
-
-
Install Node.js version 14.x or later from the Node.js downloads
site. (Previous versions of the driver support Node.js version 10.x or later.) -
Configure your development environment for the AWS SDK for JavaScript in Node.js
: -
Set up your AWS credentials. We recommend creating a shared credentials file.
For instructions, see Loading credentials in Node.js from the shared credentials file in the AWS SDK for JavaScript Developer Guide.
-
Set your default AWS Region. To learn how, see Setting the AWS Region.
For a complete list of available Regions, see Amazon QLDB endpoints and quotas in the AWS General Reference.
-
Next, you can download the complete tutorial sample application—or you can install only the driver in a Node.js project and run short code examples.
-
To install the QLDB driver and the AWS SDK for JavaScript in Node.js in an existing project, proceed to Installation.
-
To set up a project and run short code examples that demonstrate basic data transactions on a ledger, see the Quick start tutorial.
-
To run more in-depth examples of both data and management API operations in the complete tutorial sample application, see the Node.js tutorial.
Installation
QLDB supports the following driver versions and their Node.js dependencies.
To install the QLDB driver using npm (the
Node.js package manager)
The driver has peer dependencies on the following packages. You must also install these packages as dependencies in your project.
Using the driver to connect to a ledger
Then you can import the driver and use it to connect to a ledger. The following TypeScript code example shows how to create a driver instance for a specified ledger name and AWS Region.
For short code examples of how to run basic data transactions on a ledger, see the Cookbook reference.
Setup recommendations
Reusing connections with keep-alive
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 AWS SDK for JavaScript v3 reuses TCP connections by default. For more information and to learn how to disable reusing connections, see Reusing connections with keep-alive in Node.js in the AWS SDK for JavaScript Developer Guide.
We recommend using the default setting to reuse connections in the QLDB
driver for Node.js. During driver initialization, set the low-level client
HTTP option maxSockets
to the same value that you set for
maxConcurrentTransactions
.
For example, see the following JavaScript or TypeScript code.
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, we recommend reusing an existing connection.
To reuse connections in the QLDB driver for Node.js, use one of the following options:
-
During driver initialization, set the following low-level client HTTP options:
-
keepAlive
–true
-
maxSockets
– The same value that you set formaxConcurrentTransactions
For example, see the following JavaScript or TypeScript code.
-
-
Alternatively, you can set the
AWS_NODEJS_CONNECTION_REUSE_ENABLED
environment variable to1
. For more information, see Reusing Connections with Keep-Alive in Node.js in the AWS SDK for JavaScript Developer Guide.Note
If you set this environment variable, it affects all of the AWS services that use the AWS SDK for JavaScript.