DynamoDB: Get Last Inserted Item (Guide w/ Code Examples)

Provided by Rafal Wilinski
To get the last inserted item in a DynamoDB table using the JavaScript SDK, you can use the query
method to retrieve the item with the highest sort key (if your table has a sort key) or the highest primary key value.
You can use the ScanIndexForward
parameter set to false and Limit
parameter set to 1 to retrieve the last item.
const AWS = require('aws-sdk'); const dynamoDb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: 'your-table-name', ScanIndexForward: false, Limit: 1 }; dynamoDb.scan(params, (err, data) => { if (err) { console.log(err); } else { console.log(data.Items[0]); } });
Similar Code Examples
- DynamoDB: Delete Table
- DynamoDB: Attribute Not Null
- DynamoDB: Get By ID
- DynamoDB: Batch Get
- DynamoDB: Query Count
- DynamoDB: Query Items
- DynamoDB: Get Table
- DynamoDB: Query Group By
- DynamoDB: Delete Multiple Items in Javascript
- DynamoDB: BatchGetItem
- DynamoDB: Get Unique Values
- DynamoDB BatchWriteItem in Typescript
- DynamoDB Get in Typescript
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Query KeyConditionExpression
Tired of switching accounts and regions? Use Dynobase.
Try 7-day free trial. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase