Error: dynamodb update fail if not exists

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
To make UpdateItem fail when the item does not exist, add attribute_exists to ConditionExpression. UpdateItem otherwise behaves as an upsert. if_not_exists is an UpdateExpression function for default values, not an existence condition.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, UpdateCommand } from "@aws-sdk/lib-dynamodb";
const db = DynamoDBDocumentClient.from(new DynamoDBClient({ region: "us-east-1" }));
await db.send(new UpdateCommand({
TableName: "Orders",
Key: { pk: "ORDER#123", sk: "DETAIL" },
UpdateExpression: "SET #status = :status",
ConditionExpression: "attribute_exists(#pk)",
ExpressionAttributeNames: { "#pk": "pk", "#status": "status" },
ExpressionAttributeValues: { ":status": "SHIPPED" }
}));The condition is checked atomically against the item identified by the full key. If it is missing, handle ConditionalCheckFailedException as the expected “not found” outcome. A separate GetItem followed by an unconditional update leaves a race where the item can disappear between calls.
See conditional updates and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB TTL Not Working
- DynamoDB local error unable to access JAR file dynamodblocal.jar
- an expression attribute name used in the document path is not defined
- dynamodb cannot read properties of undefined
- moto dynamodb not working
- DynamoDB missing items
- dynamodb stream missing fields
- could not unconvert attribute dynamodb
- dynamodb unable to execute http request
- DynamoDB no attribute schema defined
- DynamoDB sorting is not supported for scan expressions
- a bytes-like object is required not binary dynamodb
- DynamoDB BatchWriteItem error
- dynamodb local unable to open database file
- localstack dynamodb not working
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase