question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@aws-sdk/lib-dynamodb incorrectly marshalls non-object types

See original GitHub issue

Describe the bug

QueryCommandInput AttributeValueList is not marshaled correctly and the query command gives me this error:

{
  "error": {
    "name": "ValidationException",
    "message": "One or more parameter values were invalid: Invalid number of argument(s) for the EQ ComparisonOperator",
    "callstack": "ValidationException: One or more parameter values were invalid: Invalid number of argument(s) for the EQ ComparisonOperator\n' +
        '    at deserializeAws_json1_0QueryCommandError (/Users/abuzhinsky/Projects/work/yaft/packages/feature-sync/node_modules/@aws-sdk/client-dynamodb/dist/cjs/protocols/Aws_json1_0.js: 2984: 41)\n' +
        '    at processTicksAndRejections (internal/process/task_queues.js: 97: 5)\n' +
        '    at async /Users/abuzhinsky/Projects/work/yaft/packages/feature-sync/node_modules/@aws-sdk/middleware-serde/dist/cjs/deserializerMiddleware.js: 6: 20\n' +
        '    at async /Users/abuzhinsky/Projects/work/yaft/packages/feature-sync/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js: 11: 20\n' +
        '    at async StandardRetryStrategy.retry (/Users/abuzhinsky/Projects/work/yaft/packages/feature-sync/node_modules/@aws-sdk/middleware-retry/dist/cjs/StandardRetryStrategy.js: 51: 46)\n' +
        '    at async /Users/abuzhinsky/Projects/work/yaft/packages/feature-sync/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js: 6: 22\n' +
        '    at async /Users/abuzhinsky/Projects/work/yaft/packages/feature-sync/node_modules/@aws-sdk/lib-dynamodb/dist/cjs/commands/QueryCommand.js: 44: 26\n' +
        '    at async /Users/abuzhinsky/Projects/work/yaft/packages/feature-sync/bin/index.js: 26: 21"
  }
}

Looks like the problem is located here - the marshall function expects only the MMember AttributeValue from the convertToAttr function.

Your environment

MacOS 11.6, Node 12

SDK version number

@aws-sdk/lib-dynamodb@3.33.0

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version

v12.22.6

Steps to reproduce

    const docClient = DynamoDBDocument.from(client)
    const res = await docClient.query({
      TableName: 'TestTable',
      KeyConditions: {
        id: {
          AttributeValueList: ['test'],
          ComparisonOperator: 'EQ'
        }
      }
    })

Observed behavior

The command input is marshaled incorrectly and the error is thrown:

{
  "TableName": "TestTable",
  "KeyConditions": {
    "id": {
      "AttributeValueList": [
        null
      ],
      "ComparisonOperator": "EQ"
    }
  }
}

Expected behavior

Expected marshaled command input is and query command should not throw an error:

{
  "TableName": "TestTable",
  "KeyConditions": {
    "id": {
      "AttributeValueList": [
        {
          "S": "test"
        }
      ],
      "ComparisonOperator": "EQ"
    }
  }
}

Additional context

Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:7

github_iconTop GitHub Comments

2reactions
cadam11commented, Jan 29, 2022

@alesso-x that is exactly the bug– ExecuteStatementCommand on lib-dynamodb is just broken until it gets fixed. As a workaround, I ended up using client-dynamodb’s version along with marshall/unmarshall from util-dynamodb.

2reactions
alesso-xcommented, Jan 31, 2022

I’m having a similar issue with using ExecuteStatementCommand. When I try to pass in parameters, I receive the following error

ValidationException: 1 validation error detected: Value '[]' at 'parameters' failed to satisfy constraint: Member must have length greater than or equal to 1

code:

import { ExecuteStatementCommand, DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
const docClient = DynamoDBDocumentClient.from(client)
const command = new ExecuteStatementCommand({
  Statement: `SELECT col_1 FROM some_table WHERE contains("col_1", ?)`,
  Parameters: ['some_param'],
});
docClient.send(command)

if I import ExecuteStatementCommand from @aws-sdk/client-dynamodb then it works

- import { ExecuteStatementCommand, DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
+ import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
+ import { ExecuteStatementCommand } from '@aws-sdk/client-dynamodb';
const command = new ExecuteStatementCommand({
  Statement: `SELECT col_1 FROM some_table WHERE contains("col_1", ?)`,
-  Parameters: ['some_param'],
+ Parameters: [{ S: 'some_param' },
});
docClient.send(command)

Am I using ExecuteStatementCommand incorrectly? I’m assuming if I’m using the version from lib-dynamodb, I do not have to create JavaScript objects with the AttributeValue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@aws-sdk/util-dynamodb | AWS SDK for JavaScript v3
Convert a DynamoDB AttributeValue object to its equivalent JavaScript type. Parameters. data: AttributeValue. The DynamoDB record to convert to JavaScript type.
Read more >
@aws-sdk/lib-dynamodb | AWS SDK for JavaScript v3
JavaScript objects passed in as parameters are marshalled into AttributeValue shapes required by Amazon DynamoDB. Responses from DynamoDB are unmarshalled into ...
Read more >
Module: AWS.DynamoDB.Converter — AWS SDK for JavaScript
Convert a JavaScript value to its equivalent DynamoDB AttributeValue type. marshall(data, options) ⇒ map. Convert a JavaScript object into a DynamoDB ...
Read more >
Using the DynamoDB Document Client - AWS SDK for ...
The DynamoDB Document client simplifies working with items by abstracting the notion of attribute values. This abstraction annotates native JavaScript types ...
Read more >
Error handling with DynamoDB - AWS Documentation
If you are not using an AWS SDK, you need to parse the content of the low-level response from ... a value that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found