0

I want to retrieve items from the table where an attribute is equal to a value I specify using dynomodb.

The SQL equivalent is.

SELECT * FROM tokens where type='app_access_token`

Code:

    copnst db = new Dynamodb.DocumentClient(credentials);

    const params = {
      TableName: 'TOKEN',
      Key: {
        type: 'app_access_token'
      }
    };

    const response = db.get(params).promise();

But I believe this will only let me get via primary key, is that right?

No SQL WorkBench Structure

enter image description here

Syntle
  • 5,168
  • 3
  • 13
  • 34
Kay
  • 17,906
  • 63
  • 162
  • 270

1 Answers1

0

DynamoDB's equivalent of SELECT * is the scan method. They are both scanning all of the table records (and hence, slow and expensive).

You can learn more about the scan method in Amazon Developer Guide or in this useful thread.

If you can, I would use a GSI with the attribute type as key, but if you still want to do it with scan method, here's how you do it:

const params = {
  TableName : 'TOKEN',
  FilterExpression : 'type = :type',
  ExpressionAttributeValues : {':type' : 'app_access_token'}
};

const documentClient = new AWS.DynamoDB.DocumentClient();

const response = documentClient.scan(params).promise();

AWS JavaScript SDK - DocumentClient Scan()

Shay Ashkenazi
  • 467
  • 1
  • 4
  • 11