Skip to content

create_vpc_peering_connection

create_vpc_peering_connection(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    peer_region: Optional[String] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    dry_run: Optional[Boolean] = None,
    vpc_id: Optional[VpcId] = None,
    peer_vpc_id: Optional[String] = None,
    peer_owner_id: Optional[String] = None,
) -> CreateVpcPeeringConnectionResult

Requests a VPC peering connection between two VPCs: a requester VPC that you own and an accepter VPC with which to create the connection. The accepter VPC can belong to another Amazon Web Services account and can be in a different Region to the requester VPC. The requester VPC and accepter VPC cannot have overlapping CIDR blocks.

Limitations and rules apply to a VPC peering connection. For more information, see the VPC peering limitations in the VPC Peering Guide.

The owner of the accepter VPC must accept the peering request to activate the peering connection. The VPC peering connection request expires after 7 days, after which it cannot be accepted or rejected.

If you create a VPC peering connection request between VPCs with overlapping CIDR blocks, the VPC peering connection has a status of failed.

Parameters:

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

    The Region code for the accepter VPC, if the accepter VPC is located in a Region other than the Region in which you make the request.

    Default: The Region in which you make the request.

  • tag_specifications (Optional[TagSpecificationList], default: None ) –

    The tags to assign to the peering connection.

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

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

    The ID of the requester VPC. You must specify this parameter in the request.

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

    The ID of the VPC with which you are creating the VPC peering connection. You must specify this parameter in the request.

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

    The Amazon Web Services account ID of the owner of the accepter VPC.

    Default: Your Amazon Web Services account ID

Raises:

Source code in docs_src/capo_ec2/_services/ec2.py
def create_vpc_peering_connection(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    peer_region: Optional["capo_ec2.types.string.String"] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    vpc_id: Optional["capo_ec2.types.vpc_id.VpcId"] = None,
    peer_vpc_id: Optional["capo_ec2.types.string.String"] = None,
    peer_owner_id: Optional["capo_ec2.types.string.String"] = None,
) -> "capo_ec2.types.create_vpc_peering_connection_result.CreateVpcPeeringConnectionResult":
    """<p>Requests a VPC peering connection between two VPCs: a requester VPC that you own and an accepter VPC with which to create the connection. The accepter VPC can belong to another Amazon Web Services account and can be in a different Region to the requester VPC. The requester VPC and accepter VPC cannot have overlapping CIDR blocks.</p> <note> <p>Limitations and rules apply to a VPC peering connection. For more information, see the <a href="https://docs.aws.amazon.com/vpc/latest/peering/vpc-peering-basics.html#vpc-peering-limitations">VPC peering limitations</a> in the <i>VPC Peering Guide</i>.</p> </note> <p>The owner of the accepter VPC must accept the peering request to activate the peering connection. The VPC peering connection request expires after 7 days, after which it cannot be accepted or rejected.</p> <p>If you create a VPC peering connection request between VPCs with overlapping CIDR blocks, the VPC peering connection has a status of <code>failed</code>.</p>

    Args:
        peer_region: <p>The Region code for the accepter VPC, if the accepter VPC is located in a Region other than the Region in which you make the request.</p> <p>Default: The Region in which you make the request.</p>
        tag_specifications: <p>The tags to assign to the peering connection.</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>
        vpc_id: <p>The ID of the requester VPC. You must specify this parameter in the request.</p>
        peer_vpc_id: <p>The ID of the VPC with which you are creating the VPC peering connection. You must specify this parameter in the request.</p>
        peer_owner_id: <p>The Amazon Web Services account ID of the owner of the accepter VPC.</p> <p>Default: Your Amazon Web Services account ID</p>

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

    def _handler(
        req: "OperationRequest[capo_ec2.types.create_vpc_peering_connection_request.CreateVpcPeeringConnectionRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.create_vpc_peering_connection_result.CreateVpcPeeringConnectionResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_vpc_peering_connection

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateVpcPeeringConnection")
    )
    input_: capo_ec2.types.create_vpc_peering_connection_request.CreateVpcPeeringConnectionRequest = {}
    if peer_region is not None:
        input_["peer_region"] = peer_region
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if vpc_id is not None:
        input_["vpc_id"] = vpc_id
    if peer_vpc_id is not None:
        input_["peer_vpc_id"] = peer_vpc_id
    if peer_owner_id is not None:
        input_["peer_owner_id"] = peer_owner_id

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