#1834 - Check item size in DynamoDB

This commit is contained in:
Bert Blommers 2019-10-05 15:20:43 +01:00
parent 2190eca96a
commit 4dec187d80
2 changed files with 25 additions and 0 deletions

View File

@ -225,6 +225,10 @@ class DynamoHandler(BaseResponse):
er = 'com.amazonaws.dynamodb.v20111205#ValidationException'
return self.error(er, 'Return values set to invalid value')
if len(str(item).encode('utf-8')) > 405000:
er = 'com.amazonaws.dynamodb.v20111205#ValidationException'
return self.error(er, 'Item size has exceeded the maximum allowed size')
if has_empty_keys_or_values(item):
return get_empty_str_error()

View File

@ -2278,6 +2278,27 @@ def test_index_with_unknown_attributes_should_fail():
ex.exception.response['Error']['Message'].should.contain(expected_exception)
# https://github.com/spulec/moto/issues/1874
@mock_dynamodb2
def test_item_size_is_under_400KB():
dynamodb = boto3.client('dynamodb', region_name='us-east-1')
dynamodb.create_table(
TableName='moto-test',
KeySchema=[{'AttributeName': 'id', 'KeyType': 'HASH'}],
AttributeDefinitions=[{'AttributeName': 'id', 'AttributeType': 'S'}],
ProvisionedThroughput={'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1}
)
with assert_raises(ClientError) as ex:
large_item = 'x' * 410 * 1000
dynamodb.put_item(
TableName='moto-test',
Item={'id': {'S': 'foo'}, 'item': {'S': large_item}})
ex.exception.response['Error']['Code'].should.equal('ValidationException')
ex.exception.response['Error']['Message'].should.equal('Item size has exceeded the maximum allowed size')
def _create_user_table():
client = boto3.client('dynamodb', region_name='us-east-1')
client.create_table(