0

I want to get the items from a dynamodb table which has recent (an attribute) value between 1 to 5. I'm writing my code for JavaScript and I am using AWS SDK V3.

I have an attribute "recent" which has values from 1 to 5.

   node.js
// Load the AWS SDK V3 files for JS
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { PutCommand, 
         BatchWriteCommand,
         DeleteCommand,
         UpdateCommand, 
         DynamoDBDocumentClient,
         paginateScan,
         ScanCommand,
         GetCommand } from "@aws-sdk/lib-dynamodb";
import { unmarshall } from "@aws-sdk/util-dynamodb";

const log = (msg) => console.log(`[SCENARIO] ${msg}`);

const dynamodbClient = new DynamoDBClient({region: "eu-west"});
const dynamodbDocClient = DynamoDBDocumentClient.from(dynamodbClient);


// Set a table name that we can use later on
const tableName = "my-database";

export const handler = async (event, context) => {
let articles = [];
    const paginatedScan = {
      TableName: tableName,
     // Scan uses a filter expression instead of a key condition expression. Scan will
     // read the entire table and then apply the filter.
      //ProjectionExpresion: "recent",
      FilterExpression: "#y between :y1 and :y2",
      ExpressionAttributeNames: { "#y": {"S": "recent" }},
      ExpressionAttributeValues: { ":y1": {"N": "1"}, ":y2": {"N": "5" }},
      ConsistentRead: true,
      Select: "ALL_ATTRIBUTES",
    };
    
    const command = new ScanCommand(paginatedScan);
    try {
    const response = await dynamodbClient.send(command);
    console.log(response.Items);
    } 
    catch (err) {
    console.error(err);
    }
}

when I run this code, I expect to get a list of attributes for response but I don't get any list, I also noticed that the code gets stuck on const response = await dynamodbClient.send(command);, it doesn't go past that, I also don't get any error on the console, the code just shows successful and nothing else.

Note that I have seen a question regarding this for SDK V2 here but it did not help.

1 Answer 1

0

You use the document client, so your parameters should match that:

const paginatedScan = {
      TableName: tableName,
      FilterExpression: "#y between :y1 and :y2",
      ExpressionAttributeNames: { "#y": "recent" },
      ExpressionAttributeValues: { ":y1": 1, ":y2": 5 }
    };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.