DynamoDB.DocumentClient Issue - Error: Number 820982911946154500 is greater than Number.MAX_SAFE_INTEGER. Use BigInt.

0

I am using v3 of the aws-sdk.

When I try to use the DynamoDB document client to put items into my DynamoDB table, I receive the error Number 1213213131312312312314342 is greater than Number.MAX_SAFE_INTEGER. Use BigInt. (full stack trace below).

My code is as follows:

const dynamodb = new DynamoDBClient({ region: 'us-east-1' });
const client = DynamoDBDocumentClient.from(dynamodb, translateConfig);
const params = {
  TableName: 'Orders',
  Item: {
    PK: `${PK}`,
    SK: 'SK',
    id: id
}
const putOperation = new PutCommand(params);
await client.send(putOperation)

Id is a BigInt. I was under the impression that the DocumentDB client would marshall the number to a 'BigInt', however it looks like it is only being marshalled to a 'Number' and since it is too large to be held by a Number it is failing the validation and throwing an exception. I also tried playing around with marshall/unmarshall configurations but saw the same error. Please let me know if you know how I can fix this issue/if it is a bug in the library.

Additional information that might be helpful:

Lambda Node runtime version specified in CDK

runtime: Runtime.NODEJS_14_X,

Library versions (all sdk v3)

"@aws-sdk/client-dynamodb": "^3.53.0",
"@aws-sdk/lib-dynamodb": "^3.53.0",
"@aws-sdk/util-dynamodb": "^3.53.0",

Full stacktrace.

2022-03-09T20:11:12.601Z	9e321b10-3eb2-4042-b429-a8205e12f5b5	INFO	Error: Number 820982911946154500 is greater than Number.MAX_SAFE_INTEGER. Use BigInt. 
    at validateBigIntAndThrow (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:129:11)
    at convertToNumberAttr (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:138:9)
    at Object.convertToAttr (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:35:16)
    at /var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:118:36
    at convertToMapAttrFromEnumerableProps (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:122:7)
    at Object.convertToAttr (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:23:16)
    at /var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:118:36
    at convertToMapAttrFromEnumerableProps (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:122:7)
    at Object.convertToAttr (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/convertToAttr.js:23:16)
    at Object.marshall (/var/task/node_modules/@aws-sdk/util-dynamodb/dist-cjs/marshall.js:5:53)
asked 2 years ago85 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions