

# session\_lifecycle

The `session_lifecycle` system table contains one row for each session state change across Amazon EMR on EC2, Amazon EMR on EKS, and Amazon EMR Serverless in your account and Region. Each row records a single transition, so you can follow an interactive session through its states from creation to a terminal state. States appear exactly as the service reports them. For one aggregated row for each ended session, see [sessions](emr-system-table-sessions.md).

## Table location
<a name="emr-system-table-session-lifecycle-location"></a>

You query system tables like any other tables in Amazon S3 Tables. The catalog name contains a slash and a hyphen, so you must enclose it in double quotation marks. The following SQL query uses the fully qualified name of the `session_lifecycle` table.

```sql
SELECT * FROM "s3tablescatalog/aws-emr"."metadata"."session_lifecycle" LIMIT 10
```

## Columns
<a name="emr-system-table-session-lifecycle-columns"></a>

The following table describes the columns in the `session_lifecycle` system table.


| Column | Type | Description | 
| --- | --- | --- | 
| session\_key | string | Unique identifier for a single session, the same on every event belonging to that session. | 
| session\_name | string | Name that you gave the session when you submitted it. Null if you created the session without a name. | 
| session\_id | string | Identifier the platform assigned to this session. | 
| account\_id | string | The AWS account that owns the session. | 
| region\_name | string | The AWS Region where the session ran. | 
| event\_time | timestamp | When this lifecycle event occurred. | 
| session\_type\_enum | string | Kind of session the row describes. Valid values are spark, spark\_connect, livy, jupyter\_enterprise\_gateway, trino, and hive. | 
| state\_enum | string | The session's state exactly as the platform reports it, matching what you would see in the service console or API. | 
| platform\_enum | string | Compute platform that ran the session. Valid values are emr\_ec2, emr\_eks, and emr\_serverless. | 
| compute\_id | string | Identifier of the compute resource that ran the session. | 
| submitter\_arn | string | ARN of the IAM user or role that submitted the session. Null if you created the session without a runtime role. | 
| creation\_time | timestamp | Time that you created the session. | 
| start\_time | timestamp | When the session first became available to accept work. Null when the session failed while starting. | 
| idle\_timeout\_minutes | long | How long the session may stay idle before the platform terminates it. | 
| is\_terminal | boolean | True when the session has finished and no further events will be recorded for it. | 
| state\_reason\_message | string | Readable explanation of why the session is in its current state. Null for platforms that don't report this message. | 
| schema\_version | string | Version identifier for this row's field set. | 
| ingest\_time | timestamp | When this row was written to the table. | 

## Example queries
<a name="emr-system-table-session-lifecycle-examples"></a>

The following examples show common queries against the `session_lifecycle` table.

### Timeline of one session's state changes
<a name="emr-system-table-session-lifecycle-examples-timeline"></a>

The following SQL query traces one session through its recorded state changes. Replace the following value.
+ `{{session-key}}` is the key of the session you want to trace.

```sql
SELECT event_time, state_enum, is_terminal, state_reason_message
FROM "s3tablescatalog/aws-emr"."metadata"."session_lifecycle"
WHERE event_time >= current_timestamp - INTERVAL '7' DAY
  AND session_key = '{{session-key}}'
ORDER BY event_time
```

### Sessions whose latest recorded state is not terminal
<a name="emr-system-table-session-lifecycle-examples-active"></a>

The following SQL query returns sessions whose most recent recorded state isn't terminal.

```sql
WITH latest AS (
  SELECT *,
         ROW_NUMBER() OVER (
           PARTITION BY session_key
           ORDER BY event_time DESC, ingest_time DESC) AS rn
  FROM "s3tablescatalog/aws-emr"."metadata"."session_lifecycle"
  WHERE event_time >= current_timestamp - INTERVAL '2' DAY)
SELECT platform_enum, compute_id, session_id, state_enum, event_time
FROM latest
WHERE rn = 1 AND NOT is_terminal
```

This query reflects the latest delivered transition, which can lag by the delivery delay. For live status, use the platform console or API.