DynamoDB: Attribute Not Null (Guide w/ Code Examples)

Provided by Rafal Wilinski
Last updated: October 23rd, 2026
An absent attribute and an attribute holding DynamoDB NULL are different. Combine attribute_exists with NOT attribute_type to keep only present, non-NULL values.
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", FilterExpression: "attribute_exists(#email) AND NOT attribute_type(#email, :nullType)", ExpressionAttributeNames: { "#pk": "pk", "#email": "email" }, ExpressionAttributeValues: { ":pk": "CUSTOMER#123", ":nullType": "NULL" }, ExclusiveStartKey: lastKey, })); for (const item of page.Items ?? []) console.log(item); lastKey = page.LastEvaluatedKey; } while (lastKey && Object.keys(lastKey).length > 0);
This filter retains an empty String because empty and NULL are different values. Filters run after reading; continue pagination even when a filtered page contains no items.
Reference: AWS Query API. For related access patterns, see DynamoDB query examples.
Similar Code Examples
- DynamoDB: GetItem
- DynamoDB: Query Group By
- DynamoDB: Bulk Insert
- DynamoDB: Query Ends With
- DynamoDB: Query Items
- DynamoDB: Get Random Item
- DynamoDB: Query Count
- DynamoDB: Get Multiple Items
- DynamoDB: Get All Items
- DynamoDB: Get Unique Values
- DynamoDB: Get By ID
- DynamoDB: Get Last 10 Records
- DynamoDB: Delete Table
- DynamoDB: Batch Get
- DynamoDB Get in Typescript
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today