DynamoDB: Get Last 10 Records (Guide w/ Code Examples)
Provided by Rafal Wilinski
To retrieve the last 10 records from a DynamoDB table using the JavaScript SDK, you can use the query
or scan
methods with the following parameters:
**TableName**
: Name of the table you want to query**Limit**
: Maximum number of records you want to retrieve (in this case, 10)**ScanIndexForward**
: false ( To get the last 10 items )**KeyConditionExpression**
: 'partitionKey = :partitionKey'**ExpressionAttributeValues**
: {':partitionKey': partitionKeyValue }
var AWS = require('aws-sdk'); var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'}); var params = { TableName: 'myTable', Limit: 10, ScanIndexForward: false, KeyConditionExpression: 'partitionKey = :partitionKey', ExpressionAttributeValues: { ':partitionKey': partitionKeyValue } }; ddb.query(params, function(err, data) { if (err) { console.log("Error", err); } else { console.log("Success", data.Items); } });
Similar Code Examples
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Batch Get
- DynamoDB: Query Date Range
- DynamoDB: Create if Not Exists
- DynamoDB: Delete Table
- DynamoDB: Get Query
- DynamoDB: Get Unique Values
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: Delete Multiple Items in Javascript
- DynamoDB: Query Items
- DynamoDB: Bulk Insert
- DynamoDB: Attribute Not Null
- DynamoDB: Like
- DynamoDB: GetItem
- DynamoDB: Increment Counter
Spend less time in the AWS console, use Dynobase.
Try 7-day free trial. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase