Gathering detailed insights and metrics for @aws-sdk/lib-dynamodb
Gathering detailed insights and metrics for @aws-sdk/lib-dynamodb
Gathering detailed insights and metrics for @aws-sdk/lib-dynamodb
Gathering detailed insights and metrics for @aws-sdk/lib-dynamodb
@infra-blocks/aws-dynamodb
A convenience wrapper over @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb.
@mhlabs/dynamodb-client
A lib to simplify working with dynamodb document client in aws sdk v3.
inlaweb-lib-dynamodb
A TypeScript library for AWS DynamoDB using `@aws-sdk/client-dynamodb` v3.
dynamodb-query-builder
```javascript const { DynamoDBClient } = require('@aws-sdk/client-dynamodb') const { QueryCommand } = require('@aws-sdk/lib-dynamodb')
Modularized AWS SDK for JavaScript.
npm install @aws-sdk/lib-dynamodb
Typescript
Module System
Min. Node Version
Node Version
NPM Version
90.3
Supply Chain
99.6
Quality
96.6
Maintenance
100
Vulnerability
99.6
License
TypeScript (99.65%)
Java (0.23%)
JavaScript (0.1%)
Gherkin (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
3,358 Stars
9,565 Commits
618 Forks
42 Watchers
17 Branches
168 Contributors
Updated on Jul 11, 2025
Latest Version
3.844.0
Package Id
@aws-sdk/lib-dynamodb@3.844.0
Unpacked Size
207.73 kB
Size
25.34 kB
File Count
73
NPM Version
10.9.2
Node Version
18.20.6
Published on
Jul 09, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
The document client simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values. This abstraction annotates native JavaScript types supplied as input parameters, as well as converts annotated response data to native JavaScript types.
The document client affords developers the use of native JavaScript types
instead of AttributeValue
s to simplify the JavaScript development
experience with Amazon DynamoDB. JavaScript objects passed in as parameters
are marshalled into AttributeValue
shapes required by Amazon DynamoDB.
Responses from DynamoDB are unmarshalled into plain JavaScript objects
by the DocumentClient
. The DocumentClient
does not accept
AttributeValue
s in favor of native JavaScript types.
JavaScript Type | DynamoDB AttributeValue |
---|---|
String | S |
Number / BigInt / NumberValue | N |
Boolean | BOOL |
null | NULL |
Array | L |
Object | M |
Set<Uint8Array, Blob, ...> | BS |
Set<Number, BigInt, NumberValue> | NS |
Set<String> | SS |
Uint8Array, Buffer, File, Blob... | B |
Here is an example list which is sent to DynamoDB client in an operation:
1{ "L": [{ "NULL": true }, { "BOOL": false }, { "N": 1 }, { "S": "two" }] }
The DynamoDB document client abstracts the attribute values as follows in both input and output:
1[null, false, 1, "two"]
To create document client, you need to create DynamoDB client first as follows:
1import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; // ES6 import 2// const { DynamoDBClient } = require("@aws-sdk/client-dynamodb"); // CommonJS import 3 4// Bare-bones DynamoDB Client 5const client = new DynamoDBClient({});
1import { DynamoDB } from "@aws-sdk/client-dynamodb"; // ES6 import 2// const { DynamoDB } = require("@aws-sdk/client-dynamodb"); // CommonJS import 3 4// Full DynamoDB Client 5const client = new DynamoDB({});
The bare-bones clients are more modular. They reduce bundle size and improve loading performance over full clients as explained in blog post on modular packages in AWS SDK for JavaScript.
Once DynamoDB client is created, you can either create the bare-bones document client or full document client as follows:
1import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; // ES6 import 2// const { DynamoDBDocumentClient } = require("@aws-sdk/lib-dynamodb"); // CommonJS import 3 4// Bare-bones document client 5const ddbDocClient = DynamoDBDocumentClient.from(client); // client is DynamoDB client
1import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb"; // ES6 import 2// const { DynamoDBDocument } = require("@aws-sdk/lib-dynamodb"); // CommonJS import 3 4// Full document client 5const ddbDocClient = DynamoDBDocument.from(client); // client is DynamoDB client
The configuration for marshalling and unmarshalling can be sent as an optional second parameter during creation of document client as follows:
1export interface marshallOptions { 2 /** 3 * Whether to automatically convert empty strings, blobs, and sets to `null` 4 */ 5 convertEmptyValues?: boolean; 6 /** 7 * Whether to remove undefined values from JS arrays/Sets/objects 8 * when marshalling to DynamoDB lists/sets/maps respectively. 9 * 10 * A DynamoDB item is not itself considered a map. Only 11 * attributes of an item are examined. 12 */ 13 removeUndefinedValues?: boolean; 14 /** 15 * Whether to convert typeof object to map attribute. 16 */ 17 convertClassInstanceToMap?: boolean; 18 /** 19 * Whether to convert the top level container 20 * if it is a map or list. 21 * 22 * Default is true when using the DynamoDBDocumentClient, 23 * but false if directly using the marshall function (backwards compatibility). 24 */ 25 convertTopLevelContainer?: boolean; 26 /** 27 * Whether to allow numbers beyond Number.MAX_SAFE_INTEGER during marshalling. 28 * When set to true, allows numbers that may lose precision when converted to JavaScript numbers. 29 * When false (default), throws an error if a number exceeds Number.MAX_SAFE_INTEGER to prevent 30 * unintended loss of precision. Consider using the NumberValue type from @aws-sdk/lib-dynamodb 31 * for precise handling of large numbers. 32 */ 33 allowImpreciseNumbers?: boolean; 34} 35 36export interface unmarshallOptions { 37 /** 38 * Whether to modify how numbers are unmarshalled from DynamoDB. 39 * When set to true, returns numbers as NumberValue instances instead of native JavaScript numbers. 40 * This allows for the safe round-trip transport of numbers of arbitrary size. 41 * 42 * If a function is provided, it will be called with the string representation of numbers to handle 43 * custom conversions (e.g., using BigInt or decimal libraries). 44 */ 45 wrapNumbers?: boolean | ((value: string) => number | bigint | NumberValue | any); 46 /** 47 * When true, skip wrapping the data in `{ M: data }` before converting. 48 * 49 * Default is true when using the DynamoDBDocumentClient, 50 * but false if directly using the unmarshall function (backwards compatibility). 51 */ 52 convertWithoutMapWrapper?: boolean; 53} 54 55const marshallOptions: marshallOptions = {}; 56const unmarshallOptions: unmarshallOptions = {}; 57 58const translateConfig = { marshallOptions, unmarshallOptions }; 59 60const client = new DynamoDBClient({}); 61const ddbDocClient = DynamoDBDocument.from(client, translateConfig);
You can call the document client operations using command objects on bare-bones client as follows:
1import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb"; 2 3// ... DynamoDB client creation 4 5const ddbDocClient = DynamoDBDocumentClient.from(client); 6// Call using bare-bones client and Command object. 7await ddbDocClient.send( 8 new PutCommand({ 9 TableName, 10 Item: { 11 id: "1", 12 content: "content from DynamoDBDocumentClient", 13 }, 14 }) 15);
You can also call operations on full client as follows:
1import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb"; 2 3// ... DynamoDB client creation 4 5const ddbDocClient = DynamoDBDocument.from(client); 6// Call using full client. 7await ddbDocClient.put({ 8 TableName, 9 Item: { 10 id: "2", 11 content: "content from DynamoDBDocument", 12 }, 13});
NumberValue
.On the input or marshalling side, the class NumberValue
can be used
anywhere to represent a DynamoDB number value, even small numbers.
1import { DynamoDB } from "@aws-sdk/client-dynamodb"; 2import { NumberValue, DynamoDBDocument } from "@aws-sdk/lib-dynamodb"; 3 4// Note, the client will not validate the acceptability of the number 5// in terms of size or format. 6// It is only here to preserve your precise representation. 7const client = DynamoDBDocument.from(new DynamoDB({})); 8 9await client.put({ 10 Item: { 11 id: 1, 12 smallNumber: NumberValue.from("123"), 13 bigNumber: NumberValue.from("1000000000000000000000.000000000001"), 14 nSet: new Set([123, NumberValue.from("456"), 789]), 15 }, 16});
On the output or unmarshalling side, the class NumberValue
is used
depending on your setting for the unmarshallOptions
flag wrapnumbers
,
shown above.
1import { DynamoDB } from "@aws-sdk/client-dynamodb"; 2import { NumberValue, DynamoDBDocument } from "@aws-sdk/lib-dynamodb"; 3 4const client = DynamoDBDocument.from(new DynamoDB({})); 5 6const response = await client.get({ 7 Key: { 8 id: 1, 9 }, 10}); 11 12/** 13 * Numbers in the response may be a number, a BigInt, or a NumberValue depending 14 * on how you set `wrapNumbers`. 15 */ 16const value = response.Item.bigNumber;
You can also provide a custom function to handle number conversion during unmarshalling:
1const client = DynamoDBDocument.from(new DynamoDB({}), { 2 unmarshallOptions: { 3 // Use BigInt for all numbers 4 wrapNumbers: (str) => BigInt(str), 5 }, 6}); 7 8const response = await client.get({ 9 Key: { id: 1 }, 10}); 11 12// Numbers in response will be BigInt instead of NumberValue or regular numbers
NumberValue
does not provide a way to do mathematical operations on itself.
To do mathematical operations, take the string value of NumberValue
by calling
.toString()
and supply it to your chosen big number implementation.
The client protects against precision loss by throwing an error on large numbers, but you can either
allow imprecise values with allowImpreciseNumbers
or maintain exact precision using NumberValue
.
1const preciseValue = "34567890123456789012345678901234567890"; 2 3// 1. Default behavior - will throw error 4await client.send( 5 new PutCommand({ 6 TableName: "Table", 7 Item: { 8 id: "1", 9 number: Number(preciseValue), // Throws error: Number is greater than Number.MAX_SAFE_INTEGER 10 }, 11 }) 12); 13 14// 2. Using allowImpreciseNumbers - will store but loses precision (mimics the v2 implicit behavior) 15const impreciseClient = DynamoDBDocumentClient.from(new DynamoDBClient({}), { 16 marshallOptions: { allowImpreciseNumbers: true }, 17}); 18await impreciseClient.send( 19 new PutCommand({ 20 TableName: "Table", 21 Item: { 22 id: "2", 23 number: Number(preciseValue), // Loses precision 34567890123456790000000000000000000000n 24 }, 25 }) 26);
As with other AWS SDK for JavaScript v3 clients, you can apply middleware functions
both on the client itself and individual Command
s.
For individual Command
s, here are examples of how to add middleware before and after
both marshalling and unmarshalling. We will use QueryCommand
as an example.
Others follow the same pattern.
1import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; 2 3const client = new DynamoDBClient({ 4 /*...*/ 5}); 6const doc = DynamoDBDocumentClient.from(client); 7const command = new QueryCommand({ 8 /*...*/ 9});
Before and after marshalling:
1command.middlewareStack.addRelativeTo( 2 (next) => async (args) => { 3 console.log("pre-marshall", args.input); 4 return next(args); 5 }, 6 { 7 relation: "before", 8 toMiddleware: "DocumentMarshall", 9 } 10); 11command.middlewareStack.addRelativeTo( 12 (next) => async (args) => { 13 console.log("post-marshall", args.input); 14 return next(args); 15 }, 16 { 17 relation: "after", 18 toMiddleware: "DocumentMarshall", 19 } 20);
Before and after unmarshalling:
1command.middlewareStack.addRelativeTo( 2 (next) => async (args) => { 3 const result = await next(args); 4 console.log("pre-unmarshall", result.output.Items); 5 return result; 6 }, 7 { 8 relation: "after", // <- after for pre-unmarshall 9 toMiddleware: "DocumentUnmarshall", 10 } 11); 12command.middlewareStack.addRelativeTo( 13 (next) => async (args) => { 14 const result = await next(args); 15 console.log("post-unmarshall", result.output.Items); 16 return result; 17 }, 18 { 19 relation: "before", // <- before for post-unmarshall 20 toMiddleware: "DocumentUnmarshall", 21 } 22);
The destroy()
call on document client is a no-op as document client does not
create a new DynamoDB client. You need to call destroy()
on DynamoDB client to
clean resources used by it as shown below.
1const client = new DynamoDBClient({}); 2const ddbDocClient = DynamoDBDocumentClient.from(client); 3 4// Perform operations on document client. 5 6ddbDocClient.destroy(); // no-op 7client.destroy(); // destroys DynamoDBClient
No vulnerabilities found.
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
binaries present in source code
Details
Reason
SAST tool is not run on all commits -- score normalized to 7
Details
Reason
Found 8/30 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More