文档

AllocatePublicIpAddress - 分配固定公网IP

更新时间:

调用AllocatePublicIpAddress为一台ECS实例分配一个固定公网IP地址。

接口说明

调用该接口时,您需要注意:

  • 分配公网 IP 地址之前,实例必须处于运行中Running)或者已停止Stopped)状态。

  • 安全控制的实例的OperationLocks中标记了"LockReason" : "security"时,不能分配公网 IP 地址。

  • 一台实例只能分配一个公网 IP 地址。如果实例已经拥有一个公网 IP 地址,将报错AllocatedAlready

  • 重启实例( RebootInstance )或者启动实例( StartInstance )后,新的公网 IP 地址生效。

除分配公网 IP 之外,您还可以给 VPC 类型 ECS 实例绑定弹性公网 IP(EIP)。详情请参见 AssociateEipAddress

说明 当 VPC 类型实例绑定了 EIP 后,则无法再分配公网 IP。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。
  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:
    • 对于必选的资源类型,用背景高亮的方式表示。
    • 对于不支持资源级授权的操作,用全部资源表示。
  • 条件关键字:是指云产品自身定义的条件关键字。
  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
操作访问级别资源类型条件关键字关联操作
ecs:AllocatePublicIpAddressWrite
  • Instance
    acs:ecs:{#regionId}:{#accountId}:instance/{#instanceId}
  • ecs:tag

请求参数

名称类型必填描述示例值
InstanceIdstring

需要分配 IP 地址的实例 ID。

i-bp1gtjxuuvwj17zr****
IpAddressstring

实例的公网 IP 地址。如果该参数值为空,则默认由系统随机分配 IP 地址。

112.124.**.**
VlanIdstring

实例的 VLAN ID。

说明 该参数即将被弃用,为提高兼容性,请尽量使用其他参数。
720

返回参数

名称类型描述示例值
object
IpAddressstring

实例的公网 IP 地址。

112.124.**.**
RequestIdstring

请求 ID。

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

示例

正常返回示例

JSON格式

{
  "IpAddress": "112.124.**.**",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

错误码

HTTP status code错误码错误信息描述
400InvalidOperation.AllocateFailedThe current instance failed to allocate public IP, please try again later.-
400InvalidIpAddress.MalformedThe specified parameter "IpAddress" is not valid.-
400OperationDeniedSpecified operation is denied as your instance is in VPC.由于实例存在于 VPC 中,指定的操作不合法。
400InsufficientPublicIpIp address not found.-
400AllocateIpInvalidInstanceBandwidthOperationDenied The InternetMaxBandwidthOut of the specified instance cannot be less than 0.当前操作无效,请保证最大输出带宽大于0。
400OperationDeniedThe specified parameter "VlanId" is not valid or vlan has not enough IP address.-
400OperationDeniedThe specified instance already has a public IP.-
400OperationDenied.CloudboxNotSupportThis operation is denied, because the specified ECS instance which is in the Cloudbox dose not support PublicIp or Eip.-
400OperationDenied.DedicatedRegionNotSupportedThis operation is denied, because the specified ECS instance which is in the dedicated region dose not support PublicIp or Eip.专属云不支持的api的报错
403IncorrectInstanceStatusThe current status of the resource does not support this operation.该资源目前的状态不支持此操作。
403InstanceLockedForSecurityThe specified operation is denied as your instance is locked for security reasons.实例被安全锁定。
403InstanceExpiredOrInArrearsThe specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode).实例已过期或者欠费,请您续费或者结清后再进行操作。
403IpInUseThe specified IP is already in use.使用指定IP进行绑定时,IP已经被使用在别的机器上。
403AllocatedAlreadyThere is an IpAddress allocated already for the specified instance.使用指定 IP 进行绑定时,该实例已经被分配了别的 IP 地址。
403AllocateIp.FailThe specified instance fails to allocate ip, please try again.-
403NAT_PUBLIC_IP_BINDING_FAILEDBinding nat public ip failed.-
403NAT_PUBLIC_IP_ALLOCATE_FAILEDNat public ip binding failed.公网 IP 绑定失败。
403InvalidIpAddress.NotPublicThe specified IP is not public address.-
403AllocatedAlreadyAn IpAddress has been assigned to the specified instance.-
404InvalidInstanceId.NotFoundThe specified InstanceId does not exist.指定的实例ID未找到。
404InvalidVlanId.NotFoundThe VlanId provided does not exist in our records.指定的虚拟局域网 ID 不存在。
404InvalidIpAddress.NotFoundThe specified IP is not in the specified vlan.指定的 IP 不在指定的虚拟局域网内。
500InternalErrorThe request processing has failed due to some unknown error.内部错误,请重试。

访问错误中心查看更多错误码。

变更历史

变更时间变更内容概要操作
2023-10-10OpenAPI 错误码发生变更看变更集
变更项变更内容
错误码OpenAPI 错误码发生变更
    错误码 400 变更
    删除错误码:403
    删除错误码:404
    删除错误码:500
  • 本页导读 (1)
文档反馈