DescribeTerminalSessions

Updated at:

Queries the Session Manager session history.

Operation description

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

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 to return per page when paging in a paged query.

Maximum value: 100.

Default value: 10.

10

NextToken

string

No

The pagination token. Set the value to the NextToken value returned from the previous API call.

AAAAAdDWBF2****

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

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

NextToken

string

The pagination token returned in the current call.

AAAAAdDWBF2****

Sessions

object

Session

array<object>

The list of sessions.

array<object>

The session information.

CreationTime

string

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

2024-01-19T09:15:46Z

TargetServer

string

The destination service address in the VPC accessed through the instance.

192.168.0.246

PortNumber

integer

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

22

PrincipalId

string

The identity identifier. The value varies based on the identity type specified by IdentityType:

  • If the current user invokes the API as an Alibaba Cloud account, the Alibaba Cloud account ID is returned.

  • If the current user invokes the API as a Resource Access Management (RAM) user, the RAM user ID is returned.

  • If the current user performs role assumption, the ID of the actual delegate for the role assumption is returned.

123456xxxx

Username

string

The username used for the connection.

root

ClientIP

string

The client IP address of the remote connection.

192.168.1.1

IdentityType

string

The identity type. Valid values:

  • Account: Alibaba Cloud account.

  • RAMUser: Resource Access Management (RAM) user.

  • AssumedRoleUser: RAM role.

RAMUser

SessionId

string

The session ID.

s-hz023od0x9****

Connections

object

Connection

array<object>

The list of connection information.

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: The Cloud Assistant Agent needs to be upgraded.

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

  • MessageFormatInvalid: The message format is invalid.

  • AgentSocketClosed: Normal shutdown of the connection.

  • ClientClosed: The session management client triggered a shutdown of the connection.

  • ReadFromTargetPortFailed: When PortNumber is specified for data forwarding in StartTerminalSession, reading data from the destination port failed.

  • ReopenTargetPortFailed: When PortNumber is specified for data forwarding in StartTerminalSession, re-establishing a TCP connection to the destination port failed.

  • OpenTargetPortFailed: When PortNumber is specified for data forwarding in StartTerminalSession, establishing a TCP connection to the destination port failed.

  • WinptyPermissionDenied: For a Windows instance, failed to increase the read and execute permissions of the specified user on winpty.dll or winty-agent.exe.

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

  • ProcessSessionDataError: Processing session data failed.

  • SessionIdDuplicate: The session ID is duplicated.

  • SessionTimeout: The session timed out. A session connection is automatically disconnected after 3 hours.

  • IdleTimeout: The connection timed out. The connection is considered idle and automatically disconnected if there is no session interaction for 180 seconds.

  • HomeDirPermissionDenied: The permissions on the home folder of the user to be connected are insufficient.

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

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

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

  • ObtainUserInfoFailed: Obtaining the Username parameter information (home folder information) failed.

  • ObtainUserIdentityFailed: Obtaining the authentication information (uid, gid, and groups) for the Username parameter failed.

  • 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 was closed. The time is in ISO 8601 format and the UTC time zone.

2024-01-19T09:16:46Z

Status

string

The session status. Valid values:

  • Connecting: The connection is being established.

  • Connected: The connection is established.

  • Terminated: The session is terminated.

  • Failed: The connection failed.

Connecting

StartTime

string

The time when the connection was established. The time is in ISO 8601 format and the UTC time zone.

2024-01-19T09:16:40Z

InstanceId

string

The instance ID.

i-bp1i7gg30r52z2em****

FailedDetail

string

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

The Session Manager is closed normally.

Examples

Success response

JSON format

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

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 service is available in the region.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.