assign_private_ip_addresses
¶
assign_private_ip_addresses(
*,
config_overrides: Optional[EC2ClientConfig] = 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
Ipv4PrefixCountoption. -
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 Prefixesoption. -
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:
-
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.
>>> 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.
>>> client.assign_private_ip_addresses(network_interface_id='eni-e5aa89a3', secondary_private_ip_address_count=2)
Source code in docs_src/capo_ec2/_services/ec2.py
3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 | |