Configure Session Record Delivery to persist Session Manager records in Simple Log Service (SLS) or OSS.
Background
To query, analyze, audit, or persist Session Manager records, or to meet security and compliance requirements, deliver the records to an SLS Logstore or an OSS bucket.
Billing
Session Record Delivery is free of charge, but you may incur costs for the following items:
-
SLS billable items, such as storage space and log index traffic.
See Billing overview.
-
OSS billable items, such as storage space and object management traffic.
See Billing overview.
Step 1: Configure the Session Record Delivery feature
Specify an SLS project and Logstore or an OSS bucket in the ECS console:
In the upper-left corner of the page, select a region and resource group.
-
In the upper-right corner of the ECS Cloud Assistant page, click Settings.
-
In the Cloud Assistant Settings dialog box, click the Session Manager Settings tab.
-
Deliver session records to SLS.
-
Select Deliver to Log Service.
-
Select an existing SLS project and Logstore.
-
If no SLS projects or Logstores exist in the selected region, click Log Service Console or Logstores to create them. Then return to the dialog box and click the
icon to refresh the list. See Manage projects and Manage a logstore. -
To query or analyze logs in SLS, you must enable indexing. See Create indexes.
-
(Optional) Specify a server-side encryption method for the Logstore. Delivered records are encrypted with the specified method. See Encrypt data.
-
-
-
Deliver session records to OSS.
-
Click Deliver to OSS.
-
Select an existing OSS bucket and enter a root directory for session records.
If no OSS buckets exist in the selected region, click OSS Console to create one. Then return to the dialog box and click the
icon to refresh the list. See Create buckets. -
(Optional) Click the
icon next to Advanced Options to specify a server-side encryption method.NoteOSS server-side encryption protects static data. Use it in scenarios that require high security or compliance. The session record objects are encrypted with the specified method. See Server-side encryption.
-
-
-
Click OK.
On first configuration, the system creates a service-linked role that grants Cloud Assistant access to SLS and OSS resources. If the role already exists, the system skips creation. See Manage the service-linked role for ECS Cloud Assistant.

Session records cannot be delivered across regions. Select the target region before you proceed.
Step 2: Use Session Manager to connect to the instance
After you connect to an instance with Session Manager, session records are automatically delivered to the specified SLS Logstore or OSS bucket.
See Connect in the ECS console.
Step 3: View session records
View session records in the SLS console or OSS console.
SLS console
Access a Logstore from the ECS console to view session record logs. You can also log on to the SLS console directly.
In the upper-left corner of the page, select a region and resource group.
-
In the upper-right corner of the ECS Cloud Assistant page, click Settings.
-
In the Cloud Assistant Settings dialog box, click the Session Manager Settings tab and select Deliver to Log Service.
-
On the right side of the Select a Logstore section, click Logstores.
-
For log query and analysis, see Query and analyze logs.
-
The following table describes the parameters in session record logs.
Parameter
Description
LoginUser
The username of the operator.
CallerUid
The account ID of the operator.
Content
The command and its output.
The command and output are separated by equal signs (=).
InstanceId
The instance ID.
SessionId
The session ID.
ChannelId
The channel ID.
TokenPrincipalId
The principal ID that performs operations after the instance is connected with a Security Token Service (STS) role through Session Manager.
-
OSS console
Access an OSS bucket from the ECS console to view session record objects. You can also log on to the OSS console directly.
In the upper-left corner of the page, select a region and resource group.
-
In the upper-right corner of the ECS Cloud Assistant page, click Settings.
-
In the Cloud Assistant Settings dialog box, click the Session Manager Settings tab and select Deliver to OSS.
-
On the right side of the Bucket section, click OSS Console.
-
Navigate to the directory of a specific session record object.
The OSS console opens at the root directory you specified. Session record objects are organized in subdirectories in the following format:
<Root directory>/<Region ID of the instance>/<Session record time (Year-Month)>/<Session record time (Day)>/<Instance ID>/<SessionId>/<ChannelId> -
Analyze a session record object.
Session record objects are in YAML format. Download them for analysis and auditing.
The following Java code parses a session record object in YAML format:
//The document parsing class of the YAML object. public static class Document { //The basic information about the session. private MetaData metaData; //The session records. private List<SessionData> sessionData; } //The basic information about the session. public static class MetaData { //The parsing version of the YAML object. private String version; //The username used to perform operations. private String loginUser; //The ID of the account used to perform operations. private Long callerUid; //The ID of the instance. private String instanceId; //The ID of the session. private String sessionId; //The ID of the channel. private String channelId; //The ID of the principal that actually performs operations after the instance is connected with an STS role by using Session Manager. private String stsTokenPrincipalId; } //The session records. public static class SessionData { //The time of the session record. private String time; //The command and corresponding output. In most cases, the command and the output are separated by closing angle brackets (>). private String content; } /** * Obtain the session records of Session Manager. * * @param deliveryFileName. The name of the YAML object. * @return. The session records. */ public Document getSessionData(String deliveryFileName) { Yaml yaml = new Yaml(new Constructor(Document.class)); File deliveryFile = new File(deliveryFileName); try (InputStream deliveryInputStream = new FileInputStream(deliveryFile)) { Document document = (Document) yaml.load(deliveryInputStream); //The basic information about the session. //MetaData metaData = document.getMetaData(); //The session records. //List<SessionData> sessionDataList = document.getSessionData(); return document; } catch (IOException exception) { // log.error(""); } return null; }
References
-
DescribeTerminalSessions: queries Session Manager session records.
-
ModifyCloudAssistantSettings: modifies Cloud Assistant feature configurations.
-
DescribeCloudAssistantSettings: queries Cloud Assistant feature configurations.