DynamoDB: Get Random Item (Guide w/ Code Examples)

Provided by Rafal Wilinski
To retrieve a random item from a DynamoDB table using the JavaScript SDK, you can use the query method and specify the ScanIndexForwardparameter as false. This will return the items in random order. To retrieve only one item, you can also specify a Limit parameter with a value of 1.
const AWS = require('aws-sdk'); const dynamoDb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: 'myTable', Limit: 1, ScanIndexForward: false }; dynamoDb.query(params, function(err, data) { if (err) { console.log(err); } else { console.log(data.Items[0]); } });
Note that ScanIndexForward parameter only works with querymethod. In case you need to use scan method, you need need to fetch all the items and select one randomly.
Similar Code Examples
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Bulk Insert
- DynamoDB: Get Last Inserted Item
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: GetItem
- DynamoDB: BatchGetItem
- DynamoDB: Delete Multiple Items in Javascript
- DynamoDB: Attribute Not Null
- DynamoDB: Query Items
- DynamoDB: Query Date Range
- DynamoDB: Query Ends With
- DynamoDB: Batch Get
- DynamoDB: Query Group By
- DynamoDB: Get Multiple Items
- DynamoDB: Get All Items
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