Skip to content

replace_route

replace_route(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    destination_prefix_list_id: Optional[PrefixListResourceId] = None,
    vpc_endpoint_id: Optional[VpcEndpointId] = None,
    local_target: Optional[Boolean] = None,
    transit_gateway_id: Optional[TransitGatewayId] = None,
    local_gateway_id: Optional[LocalGatewayId] = None,
    carrier_gateway_id: Optional[CarrierGatewayId] = None,
    core_network_arn: Optional[CoreNetworkArn] = None,
    odb_network_arn: Optional[OdbNetworkArn] = None,
    dry_run: Optional[Boolean] = None,
    route_table_id: Optional[RouteTableId] = None,
    destination_cidr_block: Optional[String] = None,
    gateway_id: Optional[RouteGatewayId] = None,
    destination_ipv6_cidr_block: Optional[String] = None,
    egress_only_internet_gateway_id: Optional[EgressOnlyInternetGatewayId] = None,
    instance_id: Optional[InstanceId] = None,
    network_interface_id: Optional[NetworkInterfaceId] = None,
    vpc_peering_connection_id: Optional[VpcPeeringConnectionId] = None,
    nat_gateway_id: Optional[NatGatewayId] = None,
) -> None

Replaces an existing route within a route table in a VPC.

You must specify either a destination CIDR block or a prefix list ID. You must also specify exactly one of the resources from the parameter list, or reset the local route to its default target.

For more information, see Route tables in the Amazon VPC User Guide.

Parameters:

  • destination_prefix_list_id (Optional[PrefixListResourceId], default: None ) –

    The ID of the prefix list for the route.

  • vpc_endpoint_id (Optional[VpcEndpointId], default: None ) –

    The ID of a VPC endpoint. Supported for Gateway Load Balancer endpoints only.

  • local_target (Optional[Boolean], default: None ) –

    Specifies whether to reset the local route to its default target (local).

  • transit_gateway_id (Optional[TransitGatewayId], default: None ) –

    The ID of a transit gateway.

  • local_gateway_id (Optional[LocalGatewayId], default: None ) –

    The ID of the local gateway.

  • carrier_gateway_id (Optional[CarrierGatewayId], default: None ) –

    [IPv4 traffic only] The ID of a carrier gateway.

  • core_network_arn (Optional[CoreNetworkArn], default: None ) –

    The Amazon Resource Name (ARN) of the core network.

  • odb_network_arn (Optional[OdbNetworkArn], default: None ) –

    The Amazon Resource Name (ARN) of the ODB network.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • route_table_id (Optional[RouteTableId], default: None ) –

    The ID of the route table.

  • destination_cidr_block (Optional[String], default: None ) –

    The IPv4 CIDR address block used for the destination match. The value that you provide must match the CIDR of an existing route in the table.

  • gateway_id (Optional[RouteGatewayId], default: None ) –

    The ID of an internet gateway or virtual private gateway.

  • destination_ipv6_cidr_block (Optional[String], default: None ) –

    The IPv6 CIDR address block used for the destination match. The value that you provide must match the CIDR of an existing route in the table.

  • egress_only_internet_gateway_id (Optional[EgressOnlyInternetGatewayId], default: None ) –

    [IPv6 traffic only] The ID of an egress-only internet gateway.

  • instance_id (Optional[InstanceId], default: None ) –

    The ID of a NAT instance in your VPC.

  • network_interface_id (Optional[NetworkInterfaceId], default: None ) –

    The ID of a network interface.

  • vpc_peering_connection_id (Optional[VpcPeeringConnectionId], default: None ) –

    The ID of a VPC peering connection.

  • nat_gateway_id (Optional[NatGatewayId], default: None ) –

    [IPv4 traffic only] The ID of a NAT gateway.

Raises:

Examples:

To replace a route This example replaces the specified route in the specified table table. The new route matches the specified CIDR and sends the traffic to the specified virtual private gateway.

>>> client.replace_route(route_table_id='rtb-22574640', destination_cidr_block='10.0.0.0/16', gateway_id='vgw-9a4cacf3')
Source code in docs_src/capo_ec2/_services/ec2.py
def replace_route(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    destination_prefix_list_id: Optional[
        "capo_ec2.types.prefix_list_resource_id.PrefixListResourceId"
    ] = None,
    vpc_endpoint_id: Optional[
        "capo_ec2.types.vpc_endpoint_id.VpcEndpointId"
    ] = None,
    local_target: Optional["capo_ec2.types.boolean.Boolean"] = None,
    transit_gateway_id: Optional[
        "capo_ec2.types.transit_gateway_id.TransitGatewayId"
    ] = None,
    local_gateway_id: Optional[
        "capo_ec2.types.local_gateway_id.LocalGatewayId"
    ] = None,
    carrier_gateway_id: Optional[
        "capo_ec2.types.carrier_gateway_id.CarrierGatewayId"
    ] = None,
    core_network_arn: Optional[
        "capo_ec2.types.core_network_arn.CoreNetworkArn"
    ] = None,
    odb_network_arn: Optional[
        "capo_ec2.types.odb_network_arn.OdbNetworkArn"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    route_table_id: Optional["capo_ec2.types.route_table_id.RouteTableId"] = None,
    destination_cidr_block: Optional["capo_ec2.types.string.String"] = None,
    gateway_id: Optional["capo_ec2.types.route_gateway_id.RouteGatewayId"] = None,
    destination_ipv6_cidr_block: Optional["capo_ec2.types.string.String"] = None,
    egress_only_internet_gateway_id: Optional[
        "capo_ec2.types.egress_only_internet_gateway_id.EgressOnlyInternetGatewayId"
    ] = None,
    instance_id: Optional["capo_ec2.types.instance_id.InstanceId"] = None,
    network_interface_id: Optional[
        "capo_ec2.types.network_interface_id.NetworkInterfaceId"
    ] = None,
    vpc_peering_connection_id: Optional[
        "capo_ec2.types.vpc_peering_connection_id.VpcPeeringConnectionId"
    ] = None,
    nat_gateway_id: Optional["capo_ec2.types.nat_gateway_id.NatGatewayId"] = None,
) -> None:
    """<p>Replaces an existing route within a route table in a VPC.</p> <p>You must specify either a destination CIDR block or a prefix list ID. You must also specify exactly one of the resources from the parameter list, or reset the local route to its default target.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Route_Tables.html">Route tables</a> in the <i>Amazon VPC User Guide</i>.</p>

    Args:
        destination_prefix_list_id: <p>The ID of the prefix list for the route.</p>
        vpc_endpoint_id: <p>The ID of a VPC endpoint. Supported for Gateway Load Balancer endpoints only.</p>
        local_target: <p>Specifies whether to reset the local route to its default target (<code>local</code>).</p>
        transit_gateway_id: <p>The ID of a transit gateway.</p>
        local_gateway_id: <p>The ID of the local gateway.</p>
        carrier_gateway_id: <p>[IPv4 traffic only] The ID of a carrier gateway.</p>
        core_network_arn: <p>The Amazon Resource Name (ARN) of the core network.</p>
        odb_network_arn: <p>The Amazon Resource Name (ARN) of the ODB network.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        route_table_id: <p>The ID of the route table.</p>
        destination_cidr_block: <p>The IPv4 CIDR address block used for the destination match. The value that you provide must match the CIDR of an existing route in the table.</p>
        gateway_id: <p>The ID of an internet gateway or virtual private gateway.</p>
        destination_ipv6_cidr_block: <p>The IPv6 CIDR address block used for the destination match. The value that you provide must match the CIDR of an existing route in the table.</p>
        egress_only_internet_gateway_id: <p>[IPv6 traffic only] The ID of an egress-only internet gateway.</p>
        instance_id: <p>The ID of a NAT instance in your VPC.</p>
        network_interface_id: <p>The ID of a network interface.</p>
        vpc_peering_connection_id: <p>The ID of a VPC peering connection.</p>
        nat_gateway_id: <p>[IPv4 traffic only] The ID of a NAT gateway.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To replace a route
        This example replaces the specified route in the specified table table. The new route matches the specified CIDR and sends the traffic to the specified virtual private gateway.

        >>> client.replace_route(route_table_id='rtb-22574640', destination_cidr_block='10.0.0.0/16', gateway_id='vgw-9a4cacf3')
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.replace_route_request.ReplaceRouteRequest]",
    ) -> OperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.replace_route

        output, http_response = (
            capo_ec2._operations.amazon_ec2.replace_route.replace_route(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ReplaceRoute")
    )
    input_: capo_ec2.types.replace_route_request.ReplaceRouteRequest = {}
    if destination_prefix_list_id is not None:
        input_["destination_prefix_list_id"] = destination_prefix_list_id
    if vpc_endpoint_id is not None:
        input_["vpc_endpoint_id"] = vpc_endpoint_id
    if local_target is not None:
        input_["local_target"] = local_target
    if transit_gateway_id is not None:
        input_["transit_gateway_id"] = transit_gateway_id
    if local_gateway_id is not None:
        input_["local_gateway_id"] = local_gateway_id
    if carrier_gateway_id is not None:
        input_["carrier_gateway_id"] = carrier_gateway_id
    if core_network_arn is not None:
        input_["core_network_arn"] = core_network_arn
    if odb_network_arn is not None:
        input_["odb_network_arn"] = odb_network_arn
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if route_table_id is not None:
        input_["route_table_id"] = route_table_id
    if destination_cidr_block is not None:
        input_["destination_cidr_block"] = destination_cidr_block
    if gateway_id is not None:
        input_["gateway_id"] = gateway_id
    if destination_ipv6_cidr_block is not None:
        input_["destination_ipv6_cidr_block"] = destination_ipv6_cidr_block
    if egress_only_internet_gateway_id is not None:
        input_["egress_only_internet_gateway_id"] = egress_only_internet_gateway_id
    if instance_id is not None:
        input_["instance_id"] = instance_id
    if network_interface_id is not None:
        input_["network_interface_id"] = network_interface_id
    if vpc_peering_connection_id is not None:
        input_["vpc_peering_connection_id"] = vpc_peering_connection_id
    if nat_gateway_id is not None:
        input_["nat_gateway_id"] = nat_gateway_id

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output