DynamoDB: Query Ends With (Guide w/ Code Examples)

Provided by Rafal Wilinski
Last updated: October 23rd, 2026
DynamoDB has no ends_with expression function. For a small item collection, query every page and apply JavaScript endsWith to a String attribute.
Install @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb, use an ES module on a supported Node.js runtime, and configure an AWS Region and credentials. The examples use an existing Orders table with String keys pk and sk unless an index or timestamp key is described.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb"; const ddb = DynamoDBDocumentClient.from(new DynamoDBClient({})); let lastKey; do { const page = await ddb.send(new QueryCommand({ TableName: "Orders", KeyConditionExpression: "#pk = :pk", ExpressionAttributeNames: { "#pk": "pk" }, ExpressionAttributeValues: { ":pk": "CUSTOMER#123" }, ExclusiveStartKey: lastKey, })); for (const item of page.Items ?? []) { if (typeof item.filename === "string" && item.filename.endsWith(".csv")) console.log(item); } lastKey = page.LastEvaluatedKey; } while (lastKey && Object.keys(lastKey).length > 0);
For repeated suffix searches, store a reversed value in an index sort key and query it with begins_with, or use a search service. Client-side filtering still reads every evaluated item.
Reference: AWS Query API. For related access patterns, see DynamoDB query examples.
Similar Code Examples
- DynamoDB: Like
- DynamoDB Get in Typescript
- DynamoDB: Query Count
- DynamoDB: Query Greater Than
- DynamoDB: Delete Table
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: BatchGetItem
- DynamoDB: Query Date Range
- DynamoDB: Attribute Not Null
- DynamoDB: Get All Items
- DynamoDB: Increment Counter
- DynamoDB: Get Last Inserted Item
- DynamoDB: Query JSON
- DynamoDB: Get Last 10 Records
- DynamoDB: Not Begins With
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today