0
0
DynamodbDebug / FixBeginner · 4 min read

How to Fix Item Size Limit Exceeded in DynamoDB

The 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.

javascript
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');
});
Output
Error: Item size has exceeded the maximum allowed size of 400 KB
🔧

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.

javascript
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);
Output
Success
🛡️

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.

Key Takeaways

DynamoDB items cannot exceed 400 KB in size.
Split large data into multiple smaller items or use external storage like S3.
Compress large attributes before saving to reduce size.
Design your data model to keep item sizes small and manageable.
Monitor and test item sizes during development to prevent errors.