diff --git a/moto/dynamodb2/responses.py b/moto/dynamodb2/responses.py index fba153c6f..e1d669c58 100644 --- a/moto/dynamodb2/responses.py +++ b/moto/dynamodb2/responses.py @@ -179,8 +179,20 @@ class DynamoHandler(BaseResponse): # getting attribute definition attr = body["AttributeDefinitions"] # getting the indexes - global_indexes = body.get("GlobalSecondaryIndexes", []) - local_secondary_indexes = body.get("LocalSecondaryIndexes", []) + global_indexes = body.get("GlobalSecondaryIndexes") + if global_indexes == []: + return self.error( + "ValidationException", + "One or more parameter values were invalid: List of GlobalSecondaryIndexes is empty", + ) + global_indexes = global_indexes or [] + local_secondary_indexes = body.get("LocalSecondaryIndexes") + if local_secondary_indexes == []: + return self.error( + "ValidationException", + "One or more parameter values were invalid: List of LocalSecondaryIndexes is empty", + ) + local_secondary_indexes = local_secondary_indexes or [] # Verify AttributeDefinitions list all expected_attrs = [] expected_attrs.extend([key["AttributeName"] for key in key_schema]) diff --git a/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py b/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py index c241f3bd9..61b5e0354 100644 --- a/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py +++ b/tests/test_dynamodb2/exceptions/test_dynamodb_exceptions.py @@ -428,3 +428,41 @@ def test_hash_key_can_only_use_equals_operations(operator): err = exc.value.response["Error"] err["Code"].should.equal("ValidationException") err["Message"].should.equal("Query key condition not supported") + + +@mock_dynamodb2 +def test_creating_table_with_0_local_indexes(): + dynamodb = boto3.resource("dynamodb", region_name="us-east-1") + + with pytest.raises(ClientError) as exc: + dynamodb.create_table( + TableName="test-table", + KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}], + AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}], + ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1}, + LocalSecondaryIndexes=[], + ) + err = exc.value.response["Error"] + err["Code"].should.equal("ValidationException") + err["Message"].should.equal( + "One or more parameter values were invalid: List of LocalSecondaryIndexes is empty" + ) + + +@mock_dynamodb2 +def test_creating_table_with_0_global_indexes(): + dynamodb = boto3.resource("dynamodb", region_name="us-east-1") + + with pytest.raises(ClientError) as exc: + dynamodb.create_table( + TableName="test-table", + KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}], + AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}], + ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1}, + GlobalSecondaryIndexes=[], + ) + err = exc.value.response["Error"] + err["Code"].should.equal("ValidationException") + err["Message"].should.equal( + "One or more parameter values were invalid: List of GlobalSecondaryIndexes is empty" + )