All Products
Search
Document Center

Elastic Compute Service:AssignPrivateIpAddresses

更新時間:Dec 23, 2024

Assigns one or more secondary private IP addresses to an elastic network interface (ENI). You can specify available private IP addresses within the CIDR block of the vSwitch connected to the ENI. You can also specify a number of private IP addresses to automatically assign from the CIDR block of the vSwitch to the ENI.

Operation description

Usage notes

  • The ENI to which you want to assign secondary private IP addresses must be in the Available (Available) or InUse (InUse) state.
  • When you assign private IP addresses to a primary ENI, the Elastic Compute Service (ECS) instance to which the ENI is attached must be in the Running (Running) or Stopped (Stopped) state.
  • When an ENI is in the Available state, you can assign up to 49 secondary private IP addresses to the ENI. When an ENI is attached to an instance, the number of secondary private IP addresses that can be assigned to the ENI varies based on the instance type. For more information, see Overview of instance families.
  • After the operation is called, you can obtain the assigned secondary private IP addresses from the response.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
ecs:AssignPrivateIpAddressescreate
*NetworkInterface
acs:ecs:{#regionId}:{#accountId}:eni/{#eniId}
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
RegionIdstringYes

The region ID of the ENI. You can call the DescribeRegions operation to query the most recent region list.

cn-hangzhou
NetworkInterfaceIdstringYes

The ID of the ENI.

eni-bp67acfmxazb4p****
SecondaryPrivateIpAddressCountintegerNo

The number of private IP addresses to be automatically assigned from the CIDR block of the vSwitch that is connected to the ENI.

To assign secondary private IP addresses to the ENI, you must specify PrivateIpAddress.N or SecondaryPrivateIpAddressCount but not both.

1
ClientTokenstringNo

The client token that is used to ensure the idempotence of the request. You can use the client to generate the token, but you must make sure that the token is unique among different requests. The token can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

123e4567-e89b-12d3-a456-426655440000
PrivateIpAddressarrayNo

Secondary private IP address N to be automatically assigned from the CIDR block of the vSwitch that is connected to the ENI. Valid values of N:

  • When the ENI is in the Available (Available) state, the valid values of N are 1 to 50.
  • When the ENI is in the InUse (InUse) state, the valid values of N are subject to the instance type. For more information, see Overview of instance families.

To assign secondary private IP addresses to the ENI, you must specify PrivateIpAddress.N or SecondaryPrivateIpAddressCount but not both.

stringNo

Secondary private IP address N to be automatically assigned from the CIDR block of the vSwitch that is connected to the ENI. Valid values of N:

  • When the ENI is in the Available (Available) state, the valid values of N are 1 to 50.
  • When the ENI is in the InUse (InUse) state, the valid values of N are subject to the instance type. For more information, see Overview of instance families.
Note To assign secondary private IP addresses to the ENI, you specify PrivateIpAddress.N and SecondaryPrivateIpAddressCount but not both.
10.1.**.**
Ipv4PrefixarrayNo

The IPv4 prefixes to assign to the ENI. Valid values of N: 1 to 10.

Note To assign IPv4 prefixes to the ENI, you must specify the Ipv4Prefix.N or Ipv4PrefixCount parameter, but not both.
stringNo

IPv4 prefix N to assign to the ENI. Valid values of N: 1 to 10.

Note To assign IPv4 prefixes to the ENI, you must specify the Ipv4Prefix.N or Ipv4PrefixCount parameter, but not both.
hide
Ipv4PrefixCountintegerNo

The number of IPv4 prefixes to be randomly generated for the ENI. Valid values: 1 to 10.

Note To assign IPv4 prefixes to the ENI, you must specify the Ipv4Prefix.N or Ipv4PrefixCount parameter, but not both.
hide

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E
AssignedPrivateIpAddressesSetobject

Details about the ENI and the secondary private IP addresses that are assigned to the ENI.

NetworkInterfaceIdstring

The ENI ID.

eni-bp125p95hhdhn3ot****
PrivateIpSetarray

The secondary private IP addresses that are assigned to the ENI.

PrivateIpAddressstring

The secondary private IP address that is assigned to the ENI.

192.168.**.**
Ipv4PrefixSetarray

Details about the assigned IPv4 prefixes.

Ipv4Prefixesstring

The assigned IPv4 prefix.

hide

Examples

Sample success responses

JSONformat

{
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E",
  "AssignedPrivateIpAddressesSet": {
    "NetworkInterfaceId": "eni-bp125p95hhdhn3ot****",
    "PrivateIpSet": {
      "PrivateIpAddress": [
        "192.168.**.**"
      ]
    },
    "Ipv4PrefixSet": {
      "Ipv4Prefixes": [
        "hide"
      ]
    }
  }
}

Error codes

HTTP status codeError codeError messageDescription
400ThrottlingRequest was denied due to request throttling.-
400InvalidOperation.Unsupported%s-
400UnsupportedParameter%sThe parameter is not supported.
400InvalidParameter%sThe specified parameter is invalid.
400InvalidInstanceID.Malformed%sThe specified InstanceId parameter is invalid.
400InvalidOperation.InvalidEcsState%s-
400InvalidOperation.InvalidEniState%s-
400InvalidOperation.DetachPrimaryEniNotAllowed%s-
400MissingParameter%sA parameter is not specified.
400Forbidden.RegionId%sThe service is unavailable in the current region.
400InvalidAction%sThe operation is invalid.
400InvalidPrivateIpAddress.DuplicatedSpecified private IP address is duplicated.-
400InvalidPrivateIpAddress.Malformed%s-
400InvalidSecondaryPrivateIpAddressCount.Malformed%s-
400InvalidOperation.InvalidEniStateThe operation is not allowed in the current ENI state.-
400InvalidParameter.Conflict%sThe specified parameter is invalid. Check whether parameter conflicts exist. %s is a variable. An error message is dynamically returned based on call conditions.
400InvalidOperation.InstanceNotSupportMulitipleIpAssigning private ip for instance in cloud box is unsupported.-
400IncorrectVSwitchStatusThe operation is not allowed in the current VSwitch state. Expecting state includes "Created Available", but current state is "%s".The operation is not supported in the current state of the vSwitch.
400InvalidPrivateIpAddress.DuplicatedThe specified private IP address "%s" is duplicated.The specified IP address is already in use.
400QuotaExceeded.PrivateIpAddressThere are not enough private IPs in the specified VSwitch.The current VSwitch does not have enough Ip
400InvalidStatus.InstanceIsMigratingThe ECS which ENI is attached to is migrating. Please try again later.-
400InvalidEniId.MalformedThe specified parameter "NetworkInterfaceId" is not valid. Ensure you provide the full ENI id in the form eni-xxx.NIC Id input does not meet specification
403InvalidUserType.NotSupported%sYour account does not support this operation.
403Abs.InvalidAccount.NotFound%sYour Alibaba Cloud account does not exist or your AccessKey pair has expired.
403Forbidden.NotSupportRAM%sRAM users are not authorized to perform this operation.
403Forbidden.SubUser%sYou are not authorized to manage this resource. Contact the owner of the Alibaba Cloud account for authorization.
403MaxEniCountExceeded%sThe maximum number of ENIs that can be managed has been reached.
403EniPerInstanceLimitExceeded%sThe maximum number of ENIs that can be attached to the specified instance has been reached.
403InvalidOperation.AvailabilityZoneMismatch%sThe operation is invalid.
403InvalidOperation.VpcMismatch%sThe operation is invalid. Check whether the VPC in the operation corresponds to other parameters.
403SecurityGroupInstanceLimitExceed%s-
403InvalidSecurityGroupId.NotVpc%sThe specified SecurityGroupId parameter is invalid and the network type of the security group is not VPC.
403InvalidOperation.InvalidEniType%s-
403InvalidVSwitchId.IpNotEnough%sThe number of available IP addresses on the specified vSwitch is insufficient.
403InvalidVSwitchId.IpInvalid%sThe specified private IP address is invalid.
403InvalidIp.IpAssigned%sThe specified IP address is already assigned.
403MaxEniPrivateIpsCountExceeded%sThe maximum number of secondary private IP addresses that can be assigned to the specified ENI has been exceeded. For more information, see the return value of the %s placeholder in the error message.
403Operation.Conflict%sThis operation conflicts with another operation in progress. Try again later.
403InvalidOperation.Ipv4CountExceeded%sThe operation is valid because the maximum number of IPv4 addresses has been reached.
403InvalidOperation.EniServiceManaged%sThe operation is invalid.
403InvalidIp.IpRepeated%sThe specified IP address already exists.
403InvalidIp.IpPrefixIllegalThe ip prefixes %s is/are illegal.The IP address prefix is invalid and is not in the CIDR format.
403MissingParameterThese parameters %s cannot all be empty.These parameters cannot all be empty
403InvalidIp.IpPrefixMaskIllegalThe current IP prefix mask is illegal.Illegal IP prefix mask.
403InvalidIp.IpPrefixMaskNotSameThe IP prefixes %s are illegal.The IP prefix mask must be the same.The IP prefix masks are not the same.
403InvalidIp.IpPrefixNotAvailableThe IP prefix is not available.The IP prefix is not free.
403InvalidIp.IpPrefixNotStrictThe IP prefix "%s" must be strict CIDR format.Invalid IP prefix, not strictly cidr.
403InvalidVSwitchId.IpPrefixNotEnoughThe specified VSwitch does not have enough IP prefixes.The number of IP prefixes in the specified switch is insufficient.
403InvalidIp.IpPrefixMaskInvalidThe IP prefixes mask "%s" is illegal.Ensure the mask is between %s and %s.The IP prefix mask is invalid and is not in the valid range.
403InvalidIp.IpPrefixMustInReserveSegmentThe IP prefix must be in VSwitch reserved segment. Ensure you create reserved segment for the VSwitch.The IP prefix is invalid and is not in the reserved address segment of the switch.
404InvalidEcsId.NotFound%sThe specified instance ID does not exist.
404InvalidEniId.NotFound%sThe specified ENI ID does not exist.
404InvalidVSwitchId.NotFound%sThe specified vSwitch does not exist.
404InvalidSecurityGroupId.NotFound%sThe specified security group ID does not exist.
404InvalidInstanceId.NotFound%sThe specified instance does not exist. Check whether the InstanceId parameter is valid.
404InvalidOperation.VSwitchCidrReservationNotExistThe specified VSwitch does not have CIDR reservation.The specified switch does not have a reserved segment available.
500InvalidOperation.RegionNotSupportIpPrefixThe current region does not support IP prefix feature.The region does not support IP prefix allocation.
500InternalErrorThe request processing has failed due to some unknown error, exception or failure.An internal error has occurred. Try again later.

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-12-17API Description Update. The Error code has changedView Change Details
2024-08-20The Error code has changedView Change Details
2023-08-17The Error code has changedView Change Details
2023-04-26The Error code has changedView Change Details