How to Fix Item Size Limit Exceeded in DynamoDB
Item size limit exceeded error in DynamoDB happens when an item is larger than 400 KB. To fix it, reduce the size of your item by splitting large attributes into smaller items or using compression, or redesign your data model to avoid storing too much data in one item.Why This Happens
DynamoDB has a strict limit: each item cannot be larger than 400 KB. If you try to save an item that exceeds this size, DynamoDB returns an error. This usually happens when you store large strings, big binary data, or many attributes in one item.
const AWS = require('aws-sdk'); const dynamodb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: 'MyTable', Item: { id: '123', largeData: 'A'.repeat(500000) // 500,000 characters, over 400 KB } }; dynamodb.put(params, (err, data) => { if (err) console.log('Error:', err.message); else console.log('Success'); });
The Fix
To fix this error, reduce the size of the item. You can split large attributes into multiple smaller items, store large files in S3 and save only references in DynamoDB, or compress data before saving. This keeps each item under 400 KB.
const AWS = require('aws-sdk'); const dynamodb = new AWS.DynamoDB.DocumentClient(); // Store large data in parts const params1 = { TableName: 'MyTable', Item: { id: '123', part: 1, dataChunk: 'A'.repeat(200000) // 200 KB chunk } }; const params2 = { TableName: 'MyTable', Item: { id: '123', part: 2, dataChunk: 'A'.repeat(200000) // another 200 KB chunk } }; // Save both parts separately Promise.all([ dynamodb.put(params1).promise(), dynamodb.put(params2).promise() ]).then(() => console.log('Success')).catch(console.error);
Prevention
To avoid this error in the future, design your data model to keep items small. Use references to external storage like Amazon S3 for large files. Monitor item sizes during development and consider compressing large text or binary data before saving.
- Split large data into multiple items
- Use S3 for big files and store only links in DynamoDB
- Compress data if possible
- Regularly check item sizes during development
Related Errors
Other common DynamoDB errors related to size include:
- ProvisionedThroughputExceededException: Happens when request rate is too high.
- ValidationException: Occurs if attribute names or values are invalid or too large.
- TransactionCanceledException: Can happen if combined transaction size exceeds limits.
Fixes usually involve throttling requests, validating data sizes, or splitting transactions.