Skip to content

associate_vpc_with_hosted_zone async

associate_vpc_with_hosted_zone(
    hosted_zone_id: ResourceId,
    vpc: VPC,
    *,
    config_overrides: Optional[AsyncRoute53ClientConfig] = None,
    comment: Optional[AssociateVPCComment] = None,
) -> AssociateVPCWithHostedZoneResponse

Associates an Amazon VPC with a private hosted zone.

To perform the association, the VPC and the private hosted zone must already exist. You can't convert a public hosted zone into a private hosted zone.

If you want to associate a VPC that was created by using one Amazon Web Services account with a private hosted zone that was created by using a different account, the Amazon Web Services account that created the private hosted zone must first submit a CreateVPCAssociationAuthorization request. Then the account that created the VPC must submit an AssociateVPCWithHostedZone request.

When granting access, the hosted zone and the Amazon VPC must belong to the same partition. A partition is a group of Amazon Web Services Regions. Each Amazon Web Services account is scoped to one partition.

The following are the supported partitions:

  • aws - Amazon Web Services Regions

  • aws-cn - China Regions

  • aws-us-gov - Amazon Web Services GovCloud (US) Region

For more information, see Access Management in the Amazon Web Services General Reference.

Parameters:

  • hosted_zone_id (ResourceId) –

    The ID of the private hosted zone that you want to associate an Amazon VPC with.

    Note that you can't associate a VPC with a hosted zone that doesn't have an existing VPC association.

  • vpc (VPC) –

    A complex type that contains information about the VPC that you want to associate with a private hosted zone.

  • comment (Optional[AssociateVPCComment], default: None ) –

    Optional: A comment about the association request.

Raises:

  • ConflictingDomainExists –

    The cause of this error depends on the operation that you're performing:

    • Create a public hosted zone: Two hosted zones that have the same name or that have a parent/child relationship (example.com and test.example.com) can't have any common name servers. You tried to create a hosted zone that has the same name as an existing hosted zone or that's the parent or child of an existing hosted zone, and you specified a delegation set that shares one or more name servers with the existing hosted zone. For more information, see CreateReusableDelegationSet.

    • Create a private hosted zone: A hosted zone with the specified name already exists and is already associated with the Amazon VPC that you specified.

    • Associate VPCs with a private hosted zone: The VPC that you specified is already associated with another hosted zone that has the same name.

  • InvalidInput –

    The input is not valid.

  • InvalidVPCId –

    The VPC ID that you specified either isn't a valid ID or the current account is not authorized to access this VPC.

  • LimitsExceeded –

    This operation can't be completed because the current account has reached the limit on the resource you are trying to create. To request a higher limit, create a case with the Amazon Web Services Support Center.

  • NoSuchHostedZone –

    No hosted zone exists with the ID that you specified.

  • NotAuthorizedException –

    Associating the specified VPC with the specified hosted zone has not been authorized.

  • PriorRequestNotComplete –

    If Amazon Route 53 can't process a request before the next request arrives, it will reject subsequent requests for the same hosted zone and return an HTTP 400 error (Bad request). If Route 53 returns this error repeatedly for the same request, we recommend that you wait, in intervals of increasing duration, before you try the request again.

  • PublicZoneVPCAssociation –

    You're trying to associate a VPC with a public hosted zone. Amazon Route 53 doesn't support associating a VPC with a public hosted zone.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

To associate a VPC with a hosted zone The following example associates the VPC with ID vpc-1a2b3c4d with the hosted zone with ID Z3M3LMPEXAMPLE.

>>> await client.associate_vpc_with_hosted_zone(hosted_zone_id='Z3M3LMPEXAMPLE', vpc={'VPCId': 'vpc-1a2b3c4d', 'VPCRegion': 'us-east-2'}, comment='')
Source code in docs_src/capo_route_53/_services/async_route53.py
async def associate_vpc_with_hosted_zone(
    self,
    hosted_zone_id: "capo_route_53.types.resource_id.ResourceId",
    vpc: "capo_route_53.types.vpc.VPC",
    *,
    config_overrides: Optional[AsyncRoute53ClientConfig] = None,
    comment: Optional[
        "capo_route_53.types.associate_vpc_comment.AssociateVPCComment"
    ] = None,
) -> "capo_route_53.types.associate_vpc_with_hosted_zone_response.AssociateVPCWithHostedZoneResponse":
    """<p>Associates an Amazon VPC with a private hosted zone. </p> <important> <p>To perform the association, the VPC and the private hosted zone must already exist. You can't convert a public hosted zone into a private hosted zone.</p> </important> <note> <p>If you want to associate a VPC that was created by using one Amazon Web Services account with a private hosted zone that was created by using a different account, the Amazon Web Services account that created the private hosted zone must first submit a <code>CreateVPCAssociationAuthorization</code> request. Then the account that created the VPC must submit an <code>AssociateVPCWithHostedZone</code> request.</p> </note> <note> <p>When granting access, the hosted zone and the Amazon VPC must belong to the same partition. A partition is a group of Amazon Web Services Regions. Each Amazon Web Services account is scoped to one partition.</p> <p>The following are the supported partitions:</p> <ul> <li> <p> <code>aws</code> - Amazon Web Services Regions</p> </li> <li> <p> <code>aws-cn</code> - China Regions</p> </li> <li> <p> <code>aws-us-gov</code> - Amazon Web Services GovCloud (US) Region</p> </li> </ul> <p>For more information, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html">Access Management</a> in the <i>Amazon Web Services General Reference</i>.</p> </note>

    Args:
        hosted_zone_id: <p>The ID of the private hosted zone that you want to associate an Amazon VPC with.</p> <p>Note that you can't associate a VPC with a hosted zone that doesn't have an existing VPC association.</p>
        vpc: <p>A complex type that contains information about the VPC that you want to associate with a private hosted zone.</p>
        comment: <p> <i>Optional:</i> A comment about the association request.</p>

    Raises:
        capo_route_53.errors.conflicting_domain_exists.ConflictingDomainExists: <p>The cause of this error depends on the operation that you're performing:</p> <ul> <li> <p> <b>Create a public hosted zone:</b> Two hosted zones that have the same name or that have a parent/child relationship (example.com and test.example.com) can't have any common name servers. You tried to create a hosted zone that has the same name as an existing hosted zone or that's the parent or child of an existing hosted zone, and you specified a delegation set that shares one or more name servers with the existing hosted zone. For more information, see <a href="https://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateReusableDelegationSet.html">CreateReusableDelegationSet</a>.</p> </li> <li> <p> <b>Create a private hosted zone:</b> A hosted zone with the specified name already exists and is already associated with the Amazon VPC that you specified.</p> </li> <li> <p> <b>Associate VPCs with a private hosted zone:</b> The VPC that you specified is already associated with another hosted zone that has the same name.</p> </li> </ul>
        capo_route_53.errors.invalid_input.InvalidInput: <p>The input is not valid.</p>
        capo_route_53.errors.invalid_vpc_id.InvalidVPCId: <p>The VPC ID that you specified either isn't a valid ID or the current account is not authorized to access this VPC.</p>
        capo_route_53.errors.limits_exceeded.LimitsExceeded: <p>This operation can't be completed because the current account has reached the limit on the resource you are trying to create. To request a higher limit, <a href="http://aws.amazon.com/route53-request">create a case</a> with the Amazon Web Services Support Center.</p>
        capo_route_53.errors.no_such_hosted_zone.NoSuchHostedZone: <p>No hosted zone exists with the ID that you specified.</p>
        capo_route_53.errors.not_authorized_exception.NotAuthorizedException: <p>Associating the specified VPC with the specified hosted zone has not been authorized.</p>
        capo_route_53.errors.prior_request_not_complete.PriorRequestNotComplete: <p>If Amazon Route 53 can't process a request before the next request arrives, it will reject subsequent requests for the same hosted zone and return an <code>HTTP 400 error</code> (<code>Bad request</code>). If Route 53 returns this error repeatedly for the same request, we recommend that you wait, in intervals of increasing duration, before you try the request again.</p>
        capo_route_53.errors.public_zone_vpc_association.PublicZoneVPCAssociation: <p>You're trying to associate a VPC with a public hosted zone. Amazon Route 53 doesn't support associating a VPC with a public hosted zone.</p>
        capo_route_53.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To associate a VPC with a hosted zone
        The following example associates the VPC with ID vpc-1a2b3c4d with the hosted zone with ID Z3M3LMPEXAMPLE.

        >>> await client.associate_vpc_with_hosted_zone(hosted_zone_id='Z3M3LMPEXAMPLE', vpc={'VPCId': 'vpc-1a2b3c4d', 'VPCRegion': 'us-east-2'}, comment='')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_route_53.types.associate_vpc_with_hosted_zone_request.AssociateVPCWithHostedZoneRequest]",
    ) -> AsyncOperationResponse[
        "capo_route_53.types.associate_vpc_with_hosted_zone_response.AssociateVPCWithHostedZoneResponse"
    ]:
        import capo_route_53._operations.aws_dns_v20130401.associate_vpc_with_hosted_zone

        (
            output,
            http_response,
        ) = await capo_route_53._operations.aws_dns_v20130401.associate_vpc_with_hosted_zone.async_associate_vpc_with_hosted_zone(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AssociateVPCWithHostedZone")
    )
    input_: capo_route_53.types.associate_vpc_with_hosted_zone_request.AssociateVPCWithHostedZoneRequest = {
        "hosted_zone_id": hosted_zone_id,
        "vpc": vpc,
    }
    if comment is not None:
        input_["comment"] = comment

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