diff --git a/moto/ec2/models/route_tables.py b/moto/ec2/models/route_tables.py index a2358f5d1..87b518eb3 100644 --- a/moto/ec2/models/route_tables.py +++ b/moto/ec2/models/route_tables.py @@ -514,7 +514,7 @@ class RouteBackend: for route in route_table.routes.values(): if not route.destination_cidr_block: continue - if not route.local and ip_v4_network.overlaps( - ipaddress.IPv4Network(str(route.destination_cidr_block)) + if not route.local and ip_v4_network == ipaddress.IPv4Network( + str(route.destination_cidr_block) ): raise RouteAlreadyExistsError(destination_cidr_block) diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index 9ab1fdc20..593c96217 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -664,16 +664,18 @@ def test_routes_already_exist(): ex.value.response["ResponseMetadata"].should.have.key("RequestId") ex.value.response["Error"]["Code"].should.equal("RouteAlreadyExists") - with pytest.raises(ClientError) as ex: - client.create_route( - RouteTableId=main_route_table.id, - DestinationCidrBlock=ROUTE_SUB_CIDR, - GatewayId=igw.id, - ) - - ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400) - ex.value.response["ResponseMetadata"].should.have.key("RequestId") - ex.value.response["Error"]["Code"].should.equal("RouteAlreadyExists") + # We can create a sub cidr + client.create_route( + RouteTableId=main_route_table.id, + DestinationCidrBlock=ROUTE_SUB_CIDR, + GatewayId=igw.id, + ) + # Or even a catch-all + client.create_route( + RouteTableId=main_route_table.id, + DestinationCidrBlock="0.0.0.0/0", + GatewayId=igw.id, + ) @mock_ec2