Skip to content

create_route async

create_route(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    destination_prefix_list_id: Optional[PrefixListResourceId] = None,
    vpc_endpoint_id: Optional[VpcEndpointId] = 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,
) -> CreateRouteResult

Creates a route in a route table within 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.

When determining how to route traffic, we use the route with the most specific match. For example, traffic is destined for the IPv4 address 192.0.2.3, and the route table includes the following two IPv4 routes:

  • 192.0.2.0/24 (goes to some target A)

  • 192.0.2.0/28 (goes to some target B)

Both routes apply to the traffic destined for 192.0.2.3. However, the second route in the list covers a smaller number of IP addresses and is therefore more specific, so we use that route to determine where to target the traffic.

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

Parameters:

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

    The ID of a prefix list used for the destination match.

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

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

  • 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 ) –

    The ID of the carrier gateway.

    You can only use this option when the VPC contains a subnet which is associated with a Wavelength Zone.

  • 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 for the route.

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

    The IPv4 CIDR address block used for the destination match. Routing decisions are based on the most specific match. We modify the specified CIDR block to its canonical form; for example, if you specify 100.68.0.18/18, we modify it to 100.68.0.0/18.

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

    The ID of an internet gateway or virtual private gateway attached to your VPC.

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

    The IPv6 CIDR block used for the destination match. Routing decisions are based on the most specific match.

  • 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. The operation fails if you specify an instance ID unless exactly one network interface is attached.

  • 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 create a route This example creates a route for the specified route table. The route matches all traffic (0.0.0.0/0) and routes it to the specified Internet gateway.

>>> await client.create_route(route_table_id='rtb-22574640', destination_cidr_block='0.0.0.0/0', gateway_id='igw-c0a643a9')
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def create_route(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = 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,
    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,
) -> "capo_ec2.types.create_route_result.CreateRouteResult":
    """<p>Creates a route in a route table within 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.</p> <p>When determining how to route traffic, we use the route with the most specific match. For example, traffic is destined for the IPv4 address <code>192.0.2.3</code>, and the route table includes the following two IPv4 routes:</p> <ul> <li> <p> <code>192.0.2.0/24</code> (goes to some target A)</p> </li> <li> <p> <code>192.0.2.0/28</code> (goes to some target B)</p> </li> </ul> <p>Both routes apply to the traffic destined for <code>192.0.2.3</code>. However, the second route in the list covers a smaller number of IP addresses and is therefore more specific, so we use that route to determine where to target the traffic.</p> <p>For more information about route tables, 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 a prefix list used for the destination match.</p>
        vpc_endpoint_id: <p>The ID of a VPC endpoint. Supported for Gateway Load Balancer endpoints only.</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>The ID of the carrier gateway.</p> <p>You can only use this option when the VPC contains a subnet which is associated with a Wavelength Zone.</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 for the route.</p>
        destination_cidr_block: <p>The IPv4 CIDR address block used for the destination match. Routing decisions are based on the most specific match. We modify the specified CIDR block to its canonical form; for example, if you specify <code>100.68.0.18/18</code>, we modify it to <code>100.68.0.0/18</code>.</p>
        gateway_id: <p>The ID of an internet gateway or virtual private gateway attached to your VPC.</p>
        destination_ipv6_cidr_block: <p>The IPv6 CIDR block used for the destination match. Routing decisions are based on the most specific match.</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. The operation fails if you specify an instance ID unless exactly one network interface is attached.</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 create a route
        This example creates a route for the specified route table. The route matches all traffic (0.0.0.0/0) and routes it to the specified Internet gateway.

        >>> await client.create_route(route_table_id='rtb-22574640', destination_cidr_block='0.0.0.0/0', gateway_id='igw-c0a643a9')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.create_route_request.CreateRouteRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.create_route_result.CreateRouteResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_route

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.create_route.async_create_route(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateRoute")
    )
    input_: capo_ec2.types.create_route_request.CreateRouteRequest = {}
    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 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 = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output