Skip to content

assign_private_ip_addresses async

assign_private_ip_addresses(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    ipv4_prefixes: Optional[IpPrefixList] = None,
    ipv4_prefix_count: Optional[Integer] = None,
    network_interface_id: Optional[NetworkInterfaceId] = None,
    private_ip_addresses: Optional[PrivateIpAddressStringList] = None,
    secondary_private_ip_address_count: Optional[Integer] = None,
    allow_reassignment: Optional[Boolean] = None,
) -> AssignPrivateIpAddressesResult

Assigns the specified secondary private IP addresses to the specified network interface.

You can specify specific secondary IP addresses, or you can specify the number of secondary IP addresses to be automatically assigned from the subnet's CIDR block range. The number of secondary IP addresses that you can assign to an instance varies by instance type. For more information about Elastic IP addresses, see Elastic IP Addresses in the Amazon EC2 User Guide.

When you move a secondary private IP address to another network interface, any Elastic IP address that is associated with the IP address is also moved.

Remapping an IP address is an asynchronous operation. When you move an IP address from one network interface to another, check network/interfaces/macs/mac/local-ipv4s in the instance metadata to confirm that the remapping is complete.

You must specify either the IP addresses or the IP address count in the request.

You can optionally use Prefix Delegation on the network interface. You must specify either the IPv4 Prefix Delegation prefixes, or the IPv4 Prefix Delegation count. For information, see Assigning prefixes to network interfaces in the Amazon EC2 User Guide.

Parameters:

  • ipv4_prefixes (Optional[IpPrefixList], default: None ) –

    One or more IPv4 prefixes assigned to the network interface. You can't use this option if you use the Ipv4PrefixCount option.

  • ipv4_prefix_count (Optional[Integer], default: None ) –

    The number of IPv4 prefixes that Amazon Web Services automatically assigns to the network interface. You can't use this option if you use the Ipv4 Prefixes option.

  • network_interface_id (Optional[NetworkInterfaceId], default: None ) –

    The ID of the network interface.

  • private_ip_addresses (Optional[PrivateIpAddressStringList], default: None ) –

    The IP addresses to be assigned as a secondary private IP address to the network interface. You can't specify this parameter when also specifying a number of secondary IP addresses.

    If you don't specify an IP address, Amazon EC2 automatically selects an IP address within the subnet range.

  • secondary_private_ip_address_count (Optional[Integer], default: None ) –

    The number of secondary IP addresses to assign to the network interface. You can't specify this parameter when also specifying private IP addresses.

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

    Indicates whether to allow an IP address that is already assigned to another network interface or instance to be reassigned to the specified network interface.

Raises:

Examples:

To assign a specific secondary private IP address to an interface This example assigns the specified secondary private IP address to the specified network interface.

>>> await client.assign_private_ip_addresses(network_interface_id='eni-e5aa89a3', private_ip_addresses=['10.0.0.82'])
To assign secondary private IP addresses that Amazon EC2 selects to an interface
This example assigns two secondary private IP addresses to the specified network interface. Amazon EC2 automatically assigns these IP addresses from the available IP addresses in the CIDR block range of the subnet the network interface is associated with.
>>> await client.assign_private_ip_addresses(network_interface_id='eni-e5aa89a3', secondary_private_ip_address_count=2)
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def assign_private_ip_addresses(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    ipv4_prefixes: Optional["capo_ec2.types.ip_prefix_list.IpPrefixList"] = None,
    ipv4_prefix_count: Optional["capo_ec2.types.integer.Integer"] = None,
    network_interface_id: Optional[
        "capo_ec2.types.network_interface_id.NetworkInterfaceId"
    ] = None,
    private_ip_addresses: Optional[
        "capo_ec2.types.private_ip_address_string_list.PrivateIpAddressStringList"
    ] = None,
    secondary_private_ip_address_count: Optional[
        "capo_ec2.types.integer.Integer"
    ] = None,
    allow_reassignment: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.assign_private_ip_addresses_result.AssignPrivateIpAddressesResult":
    """<p>Assigns the specified secondary private IP addresses to the specified network interface.</p> <p>You can specify specific secondary IP addresses, or you can specify the number of secondary IP addresses to be automatically assigned from the subnet's CIDR block range. The number of secondary IP addresses that you can assign to an instance varies by instance type. For more information about Elastic IP addresses, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html">Elastic IP Addresses</a> in the <i>Amazon EC2 User Guide</i>.</p> <p>When you move a secondary private IP address to another network interface, any Elastic IP address that is associated with the IP address is also moved.</p> <p>Remapping an IP address is an asynchronous operation. When you move an IP address from one network interface to another, check <code>network/interfaces/macs/mac/local-ipv4s</code> in the instance metadata to confirm that the remapping is complete.</p> <p>You must specify either the IP addresses or the IP address count in the request.</p> <p>You can optionally use Prefix Delegation on the network interface. You must specify either the IPv4 Prefix Delegation prefixes, or the IPv4 Prefix Delegation count. For information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-prefix-eni.html"> Assigning prefixes to network interfaces</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        ipv4_prefixes: <p>One or more IPv4 prefixes assigned to the network interface. You can't use this option if you use the <code>Ipv4PrefixCount</code> option.</p>
        ipv4_prefix_count: <p>The number of IPv4 prefixes that Amazon Web Services automatically assigns to the network interface. You can't use this option if you use the <code>Ipv4 Prefixes</code> option.</p>
        network_interface_id: <p>The ID of the network interface.</p>
        private_ip_addresses: <p>The IP addresses to be assigned as a secondary private IP address to the network interface. You can't specify this parameter when also specifying a number of secondary IP addresses.</p> <p>If you don't specify an IP address, Amazon EC2 automatically selects an IP address within the subnet range.</p>
        secondary_private_ip_address_count: <p>The number of secondary IP addresses to assign to the network interface. You can't specify this parameter when also specifying private IP addresses.</p>
        allow_reassignment: <p>Indicates whether to allow an IP address that is already assigned to another network interface or instance to be reassigned to the specified network interface.</p>

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

    Examples:
        To assign a specific secondary private IP address to an interface
        This example assigns the specified secondary private IP address to the specified network interface.

        >>> await client.assign_private_ip_addresses(network_interface_id='eni-e5aa89a3', private_ip_addresses=['10.0.0.82'])
        To assign secondary private IP addresses that Amazon EC2 selects to an interface
        This example assigns two secondary private IP addresses to the specified network interface. Amazon EC2 automatically assigns these IP addresses from the available IP addresses in the CIDR block range of the subnet the network interface is associated with.

        >>> await client.assign_private_ip_addresses(network_interface_id='eni-e5aa89a3', secondary_private_ip_address_count=2)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.assign_private_ip_addresses_request.AssignPrivateIpAddressesRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.assign_private_ip_addresses_result.AssignPrivateIpAddressesResult"
    ]:
        import capo_ec2._operations.amazon_ec2.assign_private_ip_addresses

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("AssignPrivateIpAddresses")
    )
    input_: capo_ec2.types.assign_private_ip_addresses_request.AssignPrivateIpAddressesRequest = {}
    if ipv4_prefixes is not None:
        input_["ipv4_prefixes"] = ipv4_prefixes
    if ipv4_prefix_count is not None:
        input_["ipv4_prefix_count"] = ipv4_prefix_count
    if network_interface_id is not None:
        input_["network_interface_id"] = network_interface_id
    if private_ip_addresses is not None:
        input_["private_ip_addresses"] = private_ip_addresses
    if secondary_private_ip_address_count is not None:
        input_["secondary_private_ip_address_count"] = (
            secondary_private_ip_address_count
        )
    if allow_reassignment is not None:
        input_["allow_reassignment"] = allow_reassignment

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