Error: dynamodb list_append if_not_exists not working

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
list_append(if_not_exists(...)) supplies a default for a missing list, but it does not create missing parent maps. Updating parent.child fails if parent is absent or is not a Map.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, UpdateCommand } from "@aws-sdk/lib-dynamodb";
const db = DynamoDBDocumentClient.from(new DynamoDBClient({}));
const result = await db.send(new UpdateCommand({
TableName: "Records",
Key: { pk: "record-1" },
UpdateExpression: "SET #items = list_append(if_not_exists(#items, :empty), :new)",
ExpressionAttributeNames: { "#items": "items" },
ExpressionAttributeValues: { ":empty": [], ":new": [{ name: "Jake" }] },
ReturnValues: "ALL_NEW",
}));This top-level list needs no parent map. For a nested list, create the parent map when the item is created, or initialize it in a separate conditional update before appending. Do not set both parent and parent.child in the same expression: their paths overlap. Account for another writer deleting or changing the parent between separate operations.
Both arguments to list_append must be Lists. if_not_exists does not replace an existing NULL or a value of the wrong type. The function name is list_append, not list_appends, and each alias and value placeholder must be defined.
See update examples and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- dynamodb cannot assign requested address
- dynamodb index does not exist
- dynamodb connection timeout
- dynamodb global secondary index not working
- DynamoDB string set may not be empty
- dynamodb number_value cannot be converted to string
- ExpressionAttributeValues contains invalid value: One or more parameter values were invalid: An AttributeValue may not contain an empty string
- DynamoDB Get not found
- dynamodb the parameter cannot be converted to a numeric value
- dynamodb no range key value present
- DynamoDB No Regionendpoint Or Serviceurl Configured
- AWS CLI DynamoDB Error Parsing Parameter
- error dynamodb streams must be enabled on the table
- DynamoDB Local NoClassDefFoundError
- failed to begin subsegment named 'amazondynamodbv2': segment cannot be found.
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
- SSH GUI Client
- Chat With Cloud
- MongoDB GUI Client
- AWS Cost Monitoring
- DynamoDB Query Builder
- DynamoDB Code Examples
- DynamoDB Node.js Queries
- DynamoDB JSON Converter
- DynamoDB UUID Generator
- DynamoDB Local Admin GUI
- DynamoDB Pricing Calculator
- DynamoDB Single-Table Design
- Best DynamoDB GUI Clients
- Dynobase vs DynoTable