Skip to content

associate_route_table async

associate_route_table(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    gateway_id: Optional[RouteGatewayId] = None,
    public_ipv4_pool: Optional[Ipv4PoolEc2Id] = None,
    dry_run: Optional[Boolean] = None,
    subnet_id: Optional[SubnetId] = None,
    route_table_id: Optional[RouteTableId] = None,
) -> AssociateRouteTableResult

Associates a subnet in your VPC or an internet gateway or virtual private gateway attached to your VPC with a route table in your VPC. This association causes traffic from the subnet or gateway to be routed according to the routes in the route table. The action returns an association ID, which you need in order to disassociate the route table later. A route table can be associated with multiple subnets.

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

Parameters:

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

    The ID of the internet gateway or virtual private gateway.

  • public_ipv4_pool (Optional[Ipv4PoolEc2Id], default: None ) –

    The ID of a public IPv4 pool. A public IPv4 pool is a pool of IPv4 addresses that you've brought to Amazon Web Services with BYOIP.

  • 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.

  • subnet_id (Optional[SubnetId], default: None ) –

    The ID of the subnet.

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

    The ID of the route table.

Raises:

Examples:

To associate a route table with a subnet This example associates the specified route table with the specified subnet.

>>> await client.associate_route_table(subnet_id='subnet-9d4a7b6', route_table_id='rtb-22574640')
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def associate_route_table(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    gateway_id: Optional["capo_ec2.types.route_gateway_id.RouteGatewayId"] = None,
    public_ipv4_pool: Optional[
        "capo_ec2.types.ipv4_pool_ec2_id.Ipv4PoolEc2Id"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    subnet_id: Optional["capo_ec2.types.subnet_id.SubnetId"] = None,
    route_table_id: Optional["capo_ec2.types.route_table_id.RouteTableId"] = None,
) -> "capo_ec2.types.associate_route_table_result.AssociateRouteTableResult":
    """<p>Associates a subnet in your VPC or an internet gateway or virtual private gateway attached to your VPC with a route table in your VPC. This association causes traffic from the subnet or gateway to be routed according to the routes in the route table. The action returns an association ID, which you need in order to disassociate the route table later. A route table can be associated with multiple subnets.</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:
        gateway_id: <p>The ID of the internet gateway or virtual private gateway.</p>
        public_ipv4_pool: <p>The ID of a public IPv4 pool. A public IPv4 pool is a pool of IPv4 addresses that you've brought to Amazon Web Services with BYOIP.</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>
        subnet_id: <p>The ID of the subnet.</p>
        route_table_id: <p>The ID of the route table.</p>

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

    Examples:
        To associate a route table with a subnet
        This example associates the specified route table with the specified subnet.

        >>> await client.associate_route_table(subnet_id='subnet-9d4a7b6', route_table_id='rtb-22574640')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.associate_route_table_request.AssociateRouteTableRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.associate_route_table_result.AssociateRouteTableResult"
    ]:
        import capo_ec2._operations.amazon_ec2.associate_route_table

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AssociateRouteTable")
    )
    input_: capo_ec2.types.associate_route_table_request.AssociateRouteTableRequest = {}
    if gateway_id is not None:
        input_["gateway_id"] = gateway_id
    if public_ipv4_pool is not None:
        input_["public_ipv4_pool"] = public_ipv4_pool
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if subnet_id is not None:
        input_["subnet_id"] = subnet_id
    if route_table_id is not None:
        input_["route_table_id"] = route_table_id

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output