DynamoDB: Create if Not Exists (Guide w/ Code Examples)

Provided by Rafal Wilinski
You can use attribute_not_exists method with the ConditionExpression parameter to create an item only if it doesn't already exist. Here's an example of how to use it with the put operation.
const AWS = require('aws-sdk'); const dynamoDb = new AWS.DynamoDB.DocumentClient(); const tableName = 'myTable'; const item = { id: '123', name: 'John' }; const params = { TableName: tableName, Item: item, ConditionExpression: 'attribute_not_exists(id)', }; dynamoDb.put(params).promise() .then(() => { console.log(Item ${item.id} created successfully ); }) .catch(err => { if (err.code === 'ConditionalCheckFailedException') { console.log(Item ${item.id} already exists ); } else { console.error(err); } });
Similar Code Examples
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: Query Ends With
- DynamoDB BatchWriteItem in Typescript
- DynamoDB Get in Typescript
- DynamoDB: BatchGetItem
- DynamoDB: Delete Table
- DynamoDB: Get All Items
- DynamoDB: Delete Multiple Items in Javascript
- DynamoDB: Query KeyConditionExpression
- DynamoDB: Batch Get
- DynamoDB: Query Items
- DynamoDB: Query Group By
- DynamoDB: Increment Counter
- DynamoDB: Not Begins With
- DynamoDB: Get Unique Values
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
- New in Dynobase 3.0
- Semantic and Vector Search
- Schema Explorer
- Visual JSON Path Filtering
- Visual Item Diff
- MCP Server for AI Tools
- Use SQL with DynamoDB
- Import CSV To DynamoDB
- Import JSON To DynamoDB
- Export DynamoDB To JSON
- Export DynamoDB To S3
- Export DynamoDB To CSV
- DynamoDB Update Item
- DynamoDB Delete All Items
- DynamoDB Delete Item
- DynamoDB Create Table
- DynamoDB Delete Table
- DynamoDB Conditional Update
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase