Skip to content

create_secondary_subnet

create_secondary_subnet(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    client_token: Optional[String] = None,
    availability_zone: Optional[AvailabilityZoneName] = None,
    availability_zone_id: Optional[AvailabilityZoneId] = None,
    dry_run: Optional[Boolean] = None,
    ipv4_cidr_block: Optional[String] = None,
    secondary_network_id: Optional[SecondaryNetworkId] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
) -> CreateSecondarySubnetResult

Creates a secondary subnet in a secondary network.

A secondary subnet CIDR block must not overlap with the CIDR block of an existing secondary subnet in the secondary network. After you create a secondary subnet, you can't change its CIDR block.

The allowed size for a secondary subnet CIDR block is between /28 netmask (16 IP addresses) and /12 netmask (1,048,576 IP addresses). Amazon reserves the first four IP addresses and the last IP address in each secondary subnet for internal use.

Parameters:

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

    Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see Ensure Idempotency.

  • availability_zone (Optional[AvailabilityZoneName], default: None ) –

    The Availability Zone for the secondary subnet. You cannot specify both AvailabilityZone and AvailabilityZoneId in the same request.

  • availability_zone_id (Optional[AvailabilityZoneId], default: None ) –

    The ID of the Availability Zone for the secondary subnet. This option is preferred over AvailabilityZone as it provides a consistent identifier across Amazon Web Services accounts. You cannot specify both AvailabilityZone and AvailabilityZoneId in the same request.

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

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

    The IPv4 CIDR block for the secondary subnet. The CIDR block size must be between /12 and /28.

  • secondary_network_id (Optional[SecondaryNetworkId], default: None ) –

    The ID of the secondary network in which to create the secondary subnet.

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

    The tags to assign to the secondary subnet.

Raises:

Examples:

To create a secondary subnet This example creates a secondary subnet with a /24 CIDR block in the specified secondary network and Availability Zone.

>>> client.create_secondary_subnet(secondary_network_id='sn-0123456789abcdef0', ipv4_cidr_block='10.0.0.0/24', availability_zone_id='use2-az1', client_token='550e8400-e29b-41d4-a716-446655440000', tag_specifications=[{'ResourceType': 'secondary-subnet', 'Tags': [{'Key': 'Name', 'Value': 'Prod Secondary Subnet'}, {'Key': 'Environment', 'Value': 'Production'}]}])
Source code in docs_src/capo_ec2/_services/ec2.py
def create_secondary_subnet(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    availability_zone: Optional[
        "capo_ec2.types.availability_zone_name.AvailabilityZoneName"
    ] = None,
    availability_zone_id: Optional[
        "capo_ec2.types.availability_zone_id.AvailabilityZoneId"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    ipv4_cidr_block: Optional["capo_ec2.types.string.String"] = None,
    secondary_network_id: Optional[
        "capo_ec2.types.secondary_network_id.SecondaryNetworkId"
    ] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
) -> "capo_ec2.types.create_secondary_subnet_result.CreateSecondarySubnetResult":
    """<p>Creates a secondary subnet in a secondary network.</p> <p>A secondary subnet CIDR block must not overlap with the CIDR block of an existing secondary subnet in the secondary network. After you create a secondary subnet, you can't change its CIDR block.</p> <p>The allowed size for a secondary subnet CIDR block is between /28 netmask (16 IP addresses) and /12 netmask (1,048,576 IP addresses). Amazon reserves the first four IP addresses and the last IP address in each secondary subnet for internal use.</p>

    Args:
        client_token: <p>Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see <a href="https://docs.aws.amazon.com/ec2/latest/devguide/ec2-api-idempotency.html">Ensure Idempotency</a>.</p>
        availability_zone: <p>The Availability Zone for the secondary subnet. You cannot specify both <code>AvailabilityZone</code> and <code>AvailabilityZoneId</code> in the same request.</p>
        availability_zone_id: <p>The ID of the Availability Zone for the secondary subnet. This option is preferred over <code>AvailabilityZone</code> as it provides a consistent identifier across Amazon Web Services accounts. You cannot specify both <code>AvailabilityZone</code> and <code>AvailabilityZoneId</code> in the same request.</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>
        ipv4_cidr_block: <p>The IPv4 CIDR block for the secondary subnet. The CIDR block size must be between /12 and /28.</p>
        secondary_network_id: <p>The ID of the secondary network in which to create the secondary subnet.</p>
        tag_specifications: <p>The tags to assign to the secondary subnet.</p>

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

    Examples:
        To create a secondary subnet
        This example creates a secondary subnet with a /24 CIDR block in the specified secondary network and Availability Zone.

        >>> client.create_secondary_subnet(secondary_network_id='sn-0123456789abcdef0', ipv4_cidr_block='10.0.0.0/24', availability_zone_id='use2-az1', client_token='550e8400-e29b-41d4-a716-446655440000', tag_specifications=[{'ResourceType': 'secondary-subnet', 'Tags': [{'Key': 'Name', 'Value': 'Prod Secondary Subnet'}, {'Key': 'Environment', 'Value': 'Production'}]}])
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.create_secondary_subnet_request.CreateSecondarySubnetRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.create_secondary_subnet_result.CreateSecondarySubnetResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_secondary_subnet

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateSecondarySubnet")
    )
    input_: capo_ec2.types.create_secondary_subnet_request.CreateSecondarySubnetRequest = {}
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if availability_zone is not None:
        input_["availability_zone"] = availability_zone
    if availability_zone_id is not None:
        input_["availability_zone_id"] = availability_zone_id
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if ipv4_cidr_block is not None:
        input_["ipv4_cidr_block"] = ipv4_cidr_block
    if secondary_network_id is not None:
        input_["secondary_network_id"] = secondary_network_id
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications

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