DynamoDB: BatchGetItem (Guide w/ Code Examples)
Provided by Rafal Wilinski
AWS JavaScript SDK's BatchGetItem
operation returns the attributes of one or more items from one or more tables. It takes an object containing the table name and an array of key objects that specify the items to be retrieved and returns a promise that resolves to an object containing the retrieved items.
Here's an example of how to use the BatchGetItem
to retrieve items from a DynamoDB table.
const AWS = require('aws-sdk'); var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'}); var params = { RequestItems: { 'TABLE_NAME': { Keys: [ {'KEY_NAME': {N: 'KEY_VALUE_1'}}, {'KEY_NAME': {N: 'KEY_VALUE_2'}}, {'KEY_NAME': {N: 'KEY_VALUE_3'}} ], ProjectionExpression: 'KEY_NAME, ATTRIBUTE' } } }; ddb.batchGetItem(params, function(err, data) { if (err) {console.log("Error", err); } else { data.Responses.TABLE_NAME.forEach(function(element, index, array) { console.log(element); }); } });
Similar Code Examples
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: Create if Not Exists
- DynamoDB: Query Items
- DynamoDB: Get Random Item
- DynamoDB: Get Last 10 Records
- DynamoDB: Like
- DynamoDB: Get All Items
- DynamoDB: Query Count
- DynamoDB: Get Last Inserted Item
- DynamoDB: Bulk Insert
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Not Between
- DynamoDB: Attribute Not Null
- DynamoDB: Query Ends With
Tired of switching accounts and regions? Use Dynobase.
Start your 7-day free trial today
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase