Skip to content

create_vpc async

create_vpc(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    cidr_block: Optional[String] = None,
    ipv6_pool: Optional[Ipv6PoolEc2Id] = None,
    ipv6_cidr_block: Optional[String] = None,
    ipv4_ipam_pool_id: Optional[IpamPoolId] = None,
    ipv4_netmask_length: Optional[NetmaskLength] = None,
    ipv6_ipam_pool_id: Optional[IpamPoolId] = None,
    ipv6_netmask_length: Optional[NetmaskLength] = None,
    ipv6_cidr_block_network_border_group: Optional[String] = None,
    vpc_encryption_control: Optional[VpcEncryptionControlConfiguration] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    dry_run: Optional[Boolean] = None,
    instance_tenancy: Optional[Tenancy] = None,
    amazon_provided_ipv6_cidr_block: Optional[Boolean] = None,
) -> CreateVpcResult

Creates a VPC with the specified CIDR blocks.

A VPC must have an associated IPv4 CIDR block. You can choose an IPv4 CIDR block or an IPAM-allocated IPv4 CIDR block. You can optionally associate an IPv6 CIDR block with a VPC. You can choose an IPv6 CIDR block, an Amazon-provided IPv6 CIDR block, an IPAM-allocated IPv6 CIDR block, or an IPv6 CIDR block that you brought to Amazon Web Services. For more information, see IP addressing for your VPCs and subnets in the Amazon VPC User Guide.

By default, each instance that you launch in the VPC has the default DHCP options, which include only a default DNS server that we provide (AmazonProvidedDNS). For more information, see DHCP option sets in the Amazon VPC User Guide.

You can specify DNS options and tenancy for a VPC when you create it. You can't change the tenancy of a VPC after you create it. For more information, see VPC configuration options in the Amazon VPC User Guide.

Parameters:

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

    The IPv4 network range for the VPC, in CIDR notation. For example, 10.0.0.0/16. 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.

  • ipv6_pool (Optional[Ipv6PoolEc2Id], default: None ) –

    The ID of an IPv6 address pool from which to allocate the IPv6 CIDR block.

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

    The IPv6 CIDR block from the IPv6 address pool. You must also specify Ipv6Pool in the request.

    To let Amazon choose the IPv6 CIDR block for you, omit this parameter.

  • ipv4_ipam_pool_id (Optional[IpamPoolId], default: None ) –

    The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. For more information, see What is IPAM? in the Amazon VPC IPAM User Guide.

  • ipv4_netmask_length (Optional[NetmaskLength], default: None ) –

    The netmask length of the IPv4 CIDR you want to allocate to this VPC from an Amazon VPC IP Address Manager (IPAM) pool. For more information about IPAM, see What is IPAM? in the Amazon VPC IPAM User Guide.

  • ipv6_ipam_pool_id (Optional[IpamPoolId], default: None ) –

    The ID of an IPv6 IPAM pool which will be used to allocate this VPC an IPv6 CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across Amazon Web Services Regions and accounts throughout your Amazon Web Services Organization. For more information, see What is IPAM? in the Amazon VPC IPAM User Guide.

  • ipv6_netmask_length (Optional[NetmaskLength], default: None ) –

    The netmask length of the IPv6 CIDR you want to allocate to this VPC from an Amazon VPC IP Address Manager (IPAM) pool. For more information about IPAM, see What is IPAM? in the Amazon VPC IPAM User Guide.

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

    The name of the location from which we advertise the IPV6 CIDR block. Use this parameter to limit the address to this location.

    You must set AmazonProvidedIpv6CidrBlock to true to use this parameter.

  • vpc_encryption_control (Optional[VpcEncryptionControlConfiguration], default: None ) –

    Specifies the encryption control configuration to apply to the VPC during creation. VPC Encryption Control enables you to enforce encryption for all data in transit within and between VPCs to meet compliance requirements.

    For more information, see Enforce VPC encryption in transit in the Amazon VPC User Guide.

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

    The tags to assign to the VPC.

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

  • instance_tenancy (Optional[Tenancy], default: None ) –

    The tenancy options for instances launched into the VPC. For default, instances are launched with shared tenancy by default. You can launch instances with any tenancy into a shared tenancy VPC. For dedicated, instances are launched as dedicated tenancy instances by default. You can only launch instances with a tenancy of dedicated or host into a dedicated tenancy VPC.

    Important: The host value cannot be used with this parameter. Use the default or dedicated values only.

    Default: default

  • amazon_provided_ipv6_cidr_block (Optional[Boolean], default: None ) –

    Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block.

Raises:

Examples:

To create a VPC This example creates a VPC with the specified CIDR block.

>>> await client.create_vpc(cidr_block='10.0.0.0/16')
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def create_vpc(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    cidr_block: Optional["capo_ec2.types.string.String"] = None,
    ipv6_pool: Optional["capo_ec2.types.ipv6_pool_ec2_id.Ipv6PoolEc2Id"] = None,
    ipv6_cidr_block: Optional["capo_ec2.types.string.String"] = None,
    ipv4_ipam_pool_id: Optional["capo_ec2.types.ipam_pool_id.IpamPoolId"] = None,
    ipv4_netmask_length: Optional[
        "capo_ec2.types.netmask_length.NetmaskLength"
    ] = None,
    ipv6_ipam_pool_id: Optional["capo_ec2.types.ipam_pool_id.IpamPoolId"] = None,
    ipv6_netmask_length: Optional[
        "capo_ec2.types.netmask_length.NetmaskLength"
    ] = None,
    ipv6_cidr_block_network_border_group: Optional[
        "capo_ec2.types.string.String"
    ] = None,
    vpc_encryption_control: Optional[
        "capo_ec2.types.vpc_encryption_control_configuration.VpcEncryptionControlConfiguration"
    ] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    instance_tenancy: Optional["capo_ec2.types.tenancy.Tenancy"] = None,
    amazon_provided_ipv6_cidr_block: Optional[
        "capo_ec2.types.boolean.Boolean"
    ] = None,
) -> "capo_ec2.types.create_vpc_result.CreateVpcResult":
    """<p>Creates a VPC with the specified CIDR blocks.</p> <p>A VPC must have an associated IPv4 CIDR block. You can choose an IPv4 CIDR block or an IPAM-allocated IPv4 CIDR block. You can optionally associate an IPv6 CIDR block with a VPC. You can choose an IPv6 CIDR block, an Amazon-provided IPv6 CIDR block, an IPAM-allocated IPv6 CIDR block, or an IPv6 CIDR block that you brought to Amazon Web Services. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-ip-addressing.html">IP addressing for your VPCs and subnets</a> in the <i>Amazon VPC User Guide</i>.</p> <p>By default, each instance that you launch in the VPC has the default DHCP options, which include only a default DNS server that we provide (AmazonProvidedDNS). For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_DHCP_Options.html">DHCP option sets</a> in the <i>Amazon VPC User Guide</i>.</p> <p>You can specify DNS options and tenancy for a VPC when you create it. You can't change the tenancy of a VPC after you create it. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc-options.html">VPC configuration options</a> in the <i>Amazon VPC User Guide</i>.</p>

    Args:
        cidr_block: <p>The IPv4 network range for the VPC, in CIDR notation. For example, <code>10.0.0.0/16</code>. 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>
        ipv6_pool: <p>The ID of an IPv6 address pool from which to allocate the IPv6 CIDR block.</p>
        ipv6_cidr_block: <p>The IPv6 CIDR block from the IPv6 address pool. You must also specify <code>Ipv6Pool</code> in the request.</p> <p>To let Amazon choose the IPv6 CIDR block for you, omit this parameter.</p>
        ipv4_ipam_pool_id: <p>The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/ipam/what-is-it-ipam.html">What is IPAM?</a> in the <i>Amazon VPC IPAM User Guide</i>. </p>
        ipv4_netmask_length: <p>The netmask length of the IPv4 CIDR you want to allocate to this VPC from an Amazon VPC IP Address Manager (IPAM) pool. For more information about IPAM, see <a href="https://docs.aws.amazon.com/vpc/latest/ipam/what-is-it-ipam.html">What is IPAM?</a> in the <i>Amazon VPC IPAM User Guide</i>.</p>
        ipv6_ipam_pool_id: <p>The ID of an IPv6 IPAM pool which will be used to allocate this VPC an IPv6 CIDR. IPAM is a VPC feature that you can use to automate your IP address management workflows including assigning, tracking, troubleshooting, and auditing IP addresses across Amazon Web Services Regions and accounts throughout your Amazon Web Services Organization. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/ipam/what-is-it-ipam.html">What is IPAM?</a> in the <i>Amazon VPC IPAM User Guide</i>.</p>
        ipv6_netmask_length: <p>The netmask length of the IPv6 CIDR you want to allocate to this VPC from an Amazon VPC IP Address Manager (IPAM) pool. For more information about IPAM, see <a href="https://docs.aws.amazon.com/vpc/latest/ipam/what-is-it-ipam.html">What is IPAM?</a> in the <i>Amazon VPC IPAM User Guide</i>.</p>
        ipv6_cidr_block_network_border_group: <p>The name of the location from which we advertise the IPV6 CIDR block. Use this parameter to limit the address to this location.</p> <p> You must set <code>AmazonProvidedIpv6CidrBlock</code> to <code>true</code> to use this parameter.</p>
        vpc_encryption_control: <p>Specifies the encryption control configuration to apply to the VPC during creation. VPC Encryption Control enables you to enforce encryption for all data in transit within and between VPCs to meet compliance requirements.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-encryption-controls.html">Enforce VPC encryption in transit</a> in the <i>Amazon VPC User Guide</i>.</p>
        tag_specifications: <p>The tags to assign to the VPC.</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>
        instance_tenancy: <p>The tenancy options for instances launched into the VPC. For <code>default</code>, instances are launched with shared tenancy by default. You can launch instances with any tenancy into a shared tenancy VPC. For <code>dedicated</code>, instances are launched as dedicated tenancy instances by default. You can only launch instances with a tenancy of <code>dedicated</code> or <code>host</code> into a dedicated tenancy VPC. </p> <p> <b>Important:</b> The <code>host</code> value cannot be used with this parameter. Use the <code>default</code> or <code>dedicated</code> values only.</p> <p>Default: <code>default</code> </p>
        amazon_provided_ipv6_cidr_block: <p>Requests an Amazon-provided IPv6 CIDR block with a /56 prefix length for the VPC. You cannot specify the range of IP addresses, or the size of the CIDR block.</p>

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

    Examples:
        To create a VPC
        This example creates a VPC with the specified CIDR block.

        >>> await client.create_vpc(cidr_block='10.0.0.0/16')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.create_vpc_request.CreateVpcRequest]",
    ) -> AsyncOperationResponse["capo_ec2.types.create_vpc_result.CreateVpcResult"]:
        import capo_ec2._operations.amazon_ec2.create_vpc

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateVpc")
    )
    input_: capo_ec2.types.create_vpc_request.CreateVpcRequest = {}
    if cidr_block is not None:
        input_["cidr_block"] = cidr_block
    if ipv6_pool is not None:
        input_["ipv6_pool"] = ipv6_pool
    if ipv6_cidr_block is not None:
        input_["ipv6_cidr_block"] = ipv6_cidr_block
    if ipv4_ipam_pool_id is not None:
        input_["ipv4_ipam_pool_id"] = ipv4_ipam_pool_id
    if ipv4_netmask_length is not None:
        input_["ipv4_netmask_length"] = ipv4_netmask_length
    if ipv6_ipam_pool_id is not None:
        input_["ipv6_ipam_pool_id"] = ipv6_ipam_pool_id
    if ipv6_netmask_length is not None:
        input_["ipv6_netmask_length"] = ipv6_netmask_length
    if ipv6_cidr_block_network_border_group is not None:
        input_["ipv6_cidr_block_network_border_group"] = (
            ipv6_cidr_block_network_border_group
        )
    if vpc_encryption_control is not None:
        input_["vpc_encryption_control"] = vpc_encryption_control
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if instance_tenancy is not None:
        input_["instance_tenancy"] = instance_tenancy
    if amazon_provided_ipv6_cidr_block is not None:
        input_["amazon_provided_ipv6_cidr_block"] = amazon_provided_ipv6_cidr_block

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