'Wy do I get an error when issuing QueryCommand in nodejs sdk v3?

I am using aws node.js sdk v3. I want to do a simple query on the table using dynamodbdocumentclient. I wanted to do just a test if query works on a simple music table which is provided by aws developer guide.

const data = await this.dynamoDBDocumentClient.send(new QueryCommand({
      TableName: "Music",
      KeyConditionExpression: "#Artist = :artist",
      ExpressionAttributeName: {
        "#Artist": "artist"

      },
      ExpressionAttributeValues: {
        ":artist": "Acme Band"
      },
    });

But when I call this I get:

TypeError: Cannot read property '0' of undefined

When I do a simple:

const data = await.this.dynamoDBDocumentClient.send(newScanCommand({TableName: "Music"});

I am getting the correct response:

            {
                "AlbumTitle": {
                    "S": "Somewhat Famous"
                },
                "Awards": {
                    "N": "1"
                },
                "Artist": {
                    "S": "No One You Know"
                },
                "SongTitle": {
                    "S": "Call Me Today"
                }
            },
            {
                "AlbumTitle": {
                    "S": "Songs About Life"
                },
                "Awards": {
                    "N": "10"
                },
                "Artist": {
                    "S": "Acme Band"
                },
                "SongTitle": {
                    "S": "Happy Day"
                }
            },
            {
                "AlbumTitle": {
                    "S": "Songs About Sadness"
                },
                "Awards": {
                    "N": "8"
                },
                "Artist": {
                    "S": "Acme Band"
                },
                "SongTitle": {
                    "S": "Sad Day"
                }
            }
        ],
        "ScannedCount": 3
    }```

What am I doing wrong? I don't get why I am getting en error.



Solution 1:[1]

I just had the same problem, and according to this guide, the ExpressionAttributeValues must follow the DynamoDB JSON schema, being so, if your artist is a string, it should be:

...
ExpressionAttributeValues: {
    ":artist": {S: "Acme Band"}
},
...

Adding this, worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dnarvaez27