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: Query Items
- DynamoDB: Get Last 10 Records
- DynamoDB: Delete Table
- DynamoDB: Get By ID
- DynamoDB Get in Typescript
- DynamoDB: GetItem
- DynamoDB: Bulk Insert
- DynamoDB: Attribute Not Null
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Query Ends With
- DynamoDB: Get Unique Values
- DynamoDB: Query JSON
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: Query Count
- DynamoDB: Query Group By
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
- New in Dynobase 3.0
- Semantic and Vector Search
- Schema Explorer
- Visual JSON Path Filtering
- Visual Item Diff
- MCP Server for AI Tools
- Use SQL with DynamoDB
- Import CSV To DynamoDB
- Import JSON To DynamoDB
- Export DynamoDB To JSON
- Export DynamoDB To S3
- Export DynamoDB To CSV
- DynamoDB Update Item
- DynamoDB Delete All Items
- DynamoDB Delete Item
- DynamoDB Create Table
- DynamoDB Delete Table
- DynamoDB Conditional Update
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase