All Products
Search
Document Center

Elastic Compute Service:DescribeTerminalSessions

Last Updated:Sep 20, 2026

Queries the session history of Session Manager.

Operation description

You can query Session Manager session records created within the last 30 days. A maximum of 1,000 successful records are retained.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:DescribeTerminalSessions

list

*Instance

acs:ecs:{#regionId}:{#accountId}:instance/{#InstanceId}

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID.

cn-hangzhou

InstanceId

string

No

The instance ID.

i-bp1i7gg30r52z2em****

SessionId

string

No

The session ID.

s-hz023od0x9****

MaxResults

integer

No

The maximum number of entries per page for a paged query.

Maximum value: 100.

Default value: 10.

10

NextToken

string

No

The pagination token. Set this parameter to the NextToken value returned in the previous API call.

AAAAAdDWBF2****

Response elements

Element

Type

Description

Example

object

NextToken

string

The pagination token returned in this call.

AAAAAdDWBF2****

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

Sessions

object

Session

array<object>

The session list.

array<object>

The session information.

ClientIP

string

The client IP address of the remote connection.

192.168.1.1

Connections

object

Connection

array<object>

The connection information list.

object

The connection information.

ClosedReason

string

The reason why the connection was closed. This parameter is returned only when the Status is Disconnected, Terminated, or Failed. Valid values:

  • InstanceNotExists: The specified instance does not exist or has been released.

  • InstanceNotRunning: The instance is not running.

  • DeliveryTimeout: The connection timed out.

  • AgentNeedUpgrade: Cloud Assistant Agent needs to be upgraded.

  • AgentNotOnline: Cloud Assistant Agent is not connected to the server.

  • MessageFormatInvalid: The message format is invalid.

  • AgentSocketClosed: The connection was closed normally.

  • ClientClosed: The session management client closed the connection.

  • ReadFromTargetPortFailed: Failed to read data from the target port during data forwarding with the PortNumber specified in StartTerminalSession.

  • ReopenTargetPortFailed: Failed to re-establish a TCP connection to the target port during data forwarding with the PortNumber specified in StartTerminalSession.

  • OpenTargetPortFailed: Failed to establish a TCP connection to the target port during data forwarding with the PortNumber specified in StartTerminalSession.

  • WinptyPermissionDenied: For Windows instances, failed to grant the specified user read and execute permissions on winpty.dll or winpty-agent.exe.

  • PasswordNameNotFound: The PasswordName specified in StartTerminalSession was not found.

  • ProcessSessionDataError: Failed to process session data.

  • SessionIdDuplicate: The session ID is duplicate.

  • SessionTimeout: The session timed out. A session connection that exceeds 3 hours is proactively disconnected.

  • IdleTimeout: The connection timed out. A connection with no session interaction for 180 seconds is considered idle and proactively disconnected.

  • HomeDirPermissionDenied: Insufficient permissions on the home directory of the user to be connected.

  • HomeDirNotFound: The home directory of the user to be connected does not exist.

  • ShellCommandPermissionDenied: Insufficient permissions on the shell program. bash or csh does not have execute permissions.

  • ShellCommandNotFound: The shell program does not exist. The bash file on Linux, the csh file on FreeBSD, or the powershell.exe file on Windows does not exist.

  • ObtainUserInfoFailed: Failed to obtain the Username parameter information (home directory information).

  • ObtainUserIdentityFailed: Failed to obtain the Username parameter authentication information (uid, gid, groups).

  • UserNotExists: The Username specified in StartTerminalSession does not exist.

  • MalformedCommandLine: Failed to parse the CommandLine specified in StartTerminalSession.

AgentNeedUpgrade

EndTime

string

The time when the connection ended. The time is displayed in ISO 8601 format in UTC.

2024-01-19T09:16:46Z

FailedDetail

string

The details of the connection failure. This parameter is returned only when the Status is Failed.

The Session Manager is closed normally.

InstanceId

string

The instance ID.

i-bp1i7gg30r52z2em****

StartTime

string

The time when the connection started. The time is displayed in ISO 8601 format in UTC.

2024-01-19T09:16:40Z

Status

string

The session status. Valid values:

  • Connecting: The session is being connected.

  • Connected: The session is connected.

  • Terminated: The session is terminated.

  • Failed: The connection failed.

Connecting

CreationTime

string

The time when the session was created. The time is displayed in ISO 8601 format in UTC.

2024-01-19T09:15:46Z

IdentityType

string

The identity type. Valid values:

  • Account: Alibaba Cloud account.

  • RAMUser: Resource Access Management (RAM) user.

  • AssumedRoleUser: RAM role.

RAMUser

PortNumber

integer

The port number of the ECS instance used for data forwarding. If no port number is configured for data forwarding, this value is empty.

22

PrincipalId

string

The identity ID. The value varies based on the IdentityType:

  • If the caller is an Alibaba Cloud account: The Alibaba Cloud account ID is returned.

  • If the caller is a Resource Access Management (RAM) user: The RAM user ID is returned.

  • If the caller invokes the API through role assumption: The actual delegate ID of the role assumption is returned.

123456xxxx

SessionId

string

The session ID.

s-hz023od0x9****

TargetServer

string

The address of the target server in the VPC accessed through the instance.

192.168.0.246

Username

string

The username used for the connection.

root

Examples

Success response

JSON format

{
  "NextToken": "AAAAAdDWBF2****",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
  "Sessions": {
    "Session": [
      {
        "ClientIP": "192.168.1.1",
        "Connections": {
          "Connection": [
            {
              "ClosedReason": "AgentNeedUpgrade",
              "EndTime": "2024-01-19T09:16:46Z",
              "FailedDetail": "The Session Manager is closed normally.",
              "InstanceId": "i-bp1i7gg30r52z2em****",
              "StartTime": "2024-01-19T09:16:40Z",
              "Status": "Connecting"
            }
          ]
        },
        "CreationTime": "2024-01-19T09:15:46Z",
        "IdentityType": "RAMUser",
        "PortNumber": 22,
        "PrincipalId": "123456xxxx",
        "SessionId": "s-hz023od0x9****",
        "TargetServer": "192.168.0.246",
        "Username": "root"
      }
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidParameter.NextToken The specified parameter NextToken is not valid. The specified parameter NextToken is illegal.
400 InvalidParameter.MaxResults The specified parameter MaxResults is not valid. The specified parameter MaxResults is illegal.
500 InternalError An error occurred when you dispatched the request. An error occurred while sending the request, please try again later.
403 InvalidParameterCharacter The specified parameter %s contains illegal characters.
403 Operation.Forbidden The operation is not permitted. The operation is not supported.
404 InvalidRegionId.NotFound The specified parameter RegionId does not exist. The specified RegionId does not exist. Check whether the product is available in this region.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.