Reputation: 1930
From AWS DynamoDB documentation:
If you define a primary key attribute as a string type attribute, the following additional constraints apply:
- For a simple primary key, the maximum length of the first attribute value (the partition key) is 2048 bytes.
- For a composite primary key, the maximum length of the second attribute value (the sort key) is 1024 bytes.
Does it mean that in case of a composite primary key, the maximum length of the partition key is not limited?
(There is a general 400 KB per item size limit, but the question is not about that)
Upvotes: 2
Views: 3476
Reputation: 1930
Mark is right. Partition key is limited to 2048 bytes without regard to primary key type (single-attribute or composite). I've just tested it from command line. Below are the commands I used. If you change 2048 to 2049 in the second command, DynamoDB will fail to add the item with ValidationException
error.
# Create test table
aws dynamodb create-table --table-name testdb5 --attribute-definitions '[{"AttributeName": "Id", "AttributeType": "S"}, {"AttributeName": "LastName", "AttributeType": "S"}]' --key-schema '[{"AttributeName": "Id", "KeyType": "HASH"}, {"AttributeName": "LastName", "KeyType": "RANGE"}]' --provisioned-throughput '{"ReadCapacityUnits": 5, "WriteCapacityUnits": 5}'
# Add an item
aws dynamodb put-item --table-name testdb5 --item '{ "Id": {"S": '$(python -c "print '\"' + 'A'*2048 + '\"'")'}, "LastName": {"S": '$(python -c "print '\"' + 'B'*1024 + '\"'")'}}'
# Delete an item
aws dynamodb delete-item --table-name testdb5 --key '{ "Id": {"S": '$(python -c "print '\"' + 'A'*2048 + '\"'")'}, "LastName": {"S": '$(python -c "print '\"' + 'B'*1024 + '\"'")'}}'
Upvotes: 0