Skip to content

attach_internet_gateway

attach_internet_gateway(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    internet_gateway_id: Optional[InternetGatewayId] = None,
    vpc_id: Optional[VpcId] = None,
) -> None

Attaches an internet gateway or a virtual private gateway to a VPC, enabling connectivity between the internet and the VPC. For more information, see Internet gateways in the Amazon VPC User Guide.

Parameters:

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

  • internet_gateway_id (Optional[InternetGatewayId], default: None ) –

    The ID of the internet gateway.

  • vpc_id (Optional[VpcId], default: None ) –

    The ID of the VPC.

Raises:

Examples:

To attach an Internet gateway to a VPC This example attaches the specified Internet gateway to the specified VPC.

>>> client.attach_internet_gateway(internet_gateway_id='igw-c0a643a9', vpc_id='vpc-a01106c2')
Source code in docs_src/capo_ec2/_services/ec2.py
def attach_internet_gateway(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    internet_gateway_id: Optional[
        "capo_ec2.types.internet_gateway_id.InternetGatewayId"
    ] = None,
    vpc_id: Optional["capo_ec2.types.vpc_id.VpcId"] = None,
) -> None:
    """<p>Attaches an internet gateway or a virtual private gateway to a VPC, enabling connectivity between the internet and the VPC. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html">Internet gateways</a> in the <i>Amazon VPC User Guide</i>.</p>

    Args:
        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>
        internet_gateway_id: <p>The ID of the internet gateway.</p>
        vpc_id: <p>The ID of the VPC.</p>

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

    Examples:
        To attach an Internet gateway to a VPC
        This example attaches the specified Internet gateway to the specified VPC.

        >>> client.attach_internet_gateway(internet_gateway_id='igw-c0a643a9', vpc_id='vpc-a01106c2')
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.attach_internet_gateway_request.AttachInternetGatewayRequest]",
    ) -> OperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.attach_internet_gateway

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AttachInternetGateway")
    )
    input_: capo_ec2.types.attach_internet_gateway_request.AttachInternetGatewayRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if internet_gateway_id is not None:
        input_["internet_gateway_id"] = internet_gateway_id
    if vpc_id is not None:
        input_["vpc_id"] = vpc_id

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