From 1d8ca4a8520bebc572a43430ed4feeeec0cefff6 Mon Sep 17 00:00:00 2001 From: Lewis Gaul Date: Thu, 22 Jun 2023 04:29:05 -0700 Subject: [PATCH] Use same structure as delete_route() for determining cidr string --- moto/ec2/models/route_tables.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/moto/ec2/models/route_tables.py b/moto/ec2/models/route_tables.py index 51c8e2e76708..9582f116746a 100644 --- a/moto/ec2/models/route_tables.py +++ b/moto/ec2/models/route_tables.py @@ -448,6 +448,11 @@ def replace_route( interface_id: Optional[str] = None, vpc_peering_connection_id: Optional[str] = None, ) -> Route: + cidr = destination_cidr_block + if destination_ipv6_cidr_block: + cidr = destination_ipv6_cidr_block + if destination_prefix_list_id: + cidr = destination_prefix_list_id route_table = self.get_route_table(route_table_id) route_id = generate_route_id( route_table.id, destination_cidr_block, destination_ipv6_cidr_block @@ -455,11 +460,6 @@ def replace_route( try: route = route_table.routes[route_id] except KeyError: - cidr = ( - destination_cidr_block - if destination_cidr_block - else destination_ipv6_cidr_block - ) # This should be 'raise InvalidRouteError(route_table_id, cidr)' in # line with the delete_route() equivalent, but for some reason AWS # returns InvalidParameterValue instead in this case.