You can call this operation to detach a RAM role from one or more ECS instances.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String No DetachInstanceRamRole

The operation that you want to perform. Set the value to DetachInstanceRamRole.

InstanceIds String Yes ["i-bp67acfmxazb4ph***", "i-bp67acfmxazb4pi***", "i-bp67acfmxazb4pj***"…]

The IDs of the instances from which you want to detach a RAM role. It can be a JSON array that consists of multiple instance IDs. You can specify a maximum of 100 instance IDs at a time. Separate multiple instance IDs with commas (,).

RegionId String Yes cn-hangzhou

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

RamRoleName String No RamRoleTest

The name of the RAM role to be detached. You can call the ListRoles operation provided by RAM to query the RAM roles that you have created.

Response parameters

Parameter Type Example Description
RequestId String 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

The ID of the request.

TotalCount Integer 1

The total number of the instances from which you attempted to detach the RAM role.

FailCount Integer 0

The number of the instances from which the RAM role failed to be detached.

RamRoleName String RamRoleTest

The name of the RAM role.

DetachInstanceRamRoleResults Array

The returned RAM role information. It is an array that consists of DetachInstanceRamRoleResult data.

InstanceId String i-bp67acfmxazb4ph***

The instance ID.

Success Boolean true

Indicates whether the RAM role was detached.

Code String 200

Indicates whether the RAM role was detached. If 200 is returned, the RAM role was detached. If any other value is returned, the RAM role failed to be detached. For more information, see Error codes.

Message String success

Indicates whether the RAM role was detached. If success is returned, the RAM role was detached. If any other value is returned, the RAM role failed to be detached. For more information, see Error codes.

InstanceRamRoleSets Array

The set of the instance RAM role data.

InstanceId String i-bp67acfmxazb4ph***

The instance ID.

RamRoleName String RamRoleTest

The name of the RAM role.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=DetachInstanceRamRole
&InstanceIds=["i-bp67acfmxazb4ph***"]
&RegionId=cn-hangzhou
&RamRoleName=RamRoleTest
&<Common request parameters>

Sample success responses

XML format

<DetachInstanceRamRoleResponse>
      <TotalCount>1</TotalCount>
      <DetachInstanceRamRoleResults>
            <DetachInstanceRamRoleResult>
                  <Message>success</Message>
                  <InstanceId>i-bp16qng6jnvt6g7tk***</InstanceId>
                  <Code>200</Code>
                  <InstanceRamRoleSets>
                        <InstanceId>i-bp16qng6jnvt6g7tk***</InstanceId>
                        <RamRoleName>RamRoleTest</RamRoleName>
                  </InstanceRamRoleSets>
            </DetachInstanceRamRoleResult>
      </DetachInstanceRamRoleResults>
      <RequestId>14D5B163-CE6C-4489-B979-DBE5D0495A63</RequestId>
      <RamRoleName></RamRoleName>
      <FailCount>0</FailCount>
</DetachInstanceRamRoleResponse>

JSON format

{
    "TotalCount": 1,
    "DetachInstanceRamRoleResults": {
        "DetachInstanceRamRoleResult": [
            {
                "Message": "success",
                "InstanceId": "i-bp16qng6jnvt6g7tk***",
                "Code": "200",
                "InstanceRamRoleSets": {
                    "InstanceId": "i-bp16qng6jnvt6g7tk***",
                    "RamRoleName": "RamRoleTest"
                }
            }
        ]
    },
    "RequestId": "14D5B163-CE6C-4489-B979-DBE5D0495A63",
    "RamRoleName": "",
    "FailCount": 0
}

Error codes

HTTP status code Error code Error message Description
400 InvalidInstanceIds.Malformed The specified instanceIds are not valid. The error message returned because the specified InstanceIds parameter is invalid.
403 InvalidNetworkType.MismatchRamRole Ram role cannot be applied to instances of Classic network type. The error message returned because instance RAM roles are applicable only to instances in VPCs, not to instances in the classic network.
403 InvalidUser.PassRoleForbidden The RAM user does not have the privilege to pass a RAM role. The error message returned because the RAM user is not authorized to pass the RAM role.

For a list of error codes, visit the API Error Center.