DynamoDB: Query Global Secondary Index in Nodejs (Guide w/ Code Examples)

Provided by Rafal Wilinski
To query a global secondary index using the AWS JavaScript SDK in a Node.js environment, you can use the query
operation.
const AWS = require('aws-sdk'); const dynamoDb = new AWS.DynamoDB(); const params = { TableName: 'myTable', IndexName: 'myIndex', KeyConditionExpression: '#key = :value', ExpressionAttributeNames: { '#key': 'myPartitionKey' }, ExpressionAttributeValues: { ':value': { S: 'myPartitionKey' } } }; dynamoDb.query(params, (err, data) => { if (err) { console.error('Error querying DynamoDB:', err); } else { console.log('Data from DynamoDB:', data); } });
This example queries a table named myTable
with a global secondary index named myIndex
. The KeyConditionExpression
parameter is used to specify the partition key and its value, and the ExpressionAttributeNames
and ExpressionAttributeValues
are used to specify the attribute name and value of the partition key.
Similar Code Examples
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: Query Group By
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: Query JSON
- DynamoDB: Increment Counter
- DynamoDB: GetItem
- DynamoDB: Get Random Item
- DynamoDB: Get All Items
- DynamoDB: BatchGetItem
- DynamoDB: Create if Not Exists
- DynamoDB: Get Last Inserted Item
- DynamoDB: Get List Of Items
- DynamoDB Get in Typescript
- DynamoDB: Attribute Not Null
- DynamoDB: Query KeyConditionExpression
Tired of switching accounts and regions? Use Dynobase.
First 7 days are. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase