

# ListSessions
<a name="API_ListSessions"></a>

Lists the sessions that the caller created in the last 24 hours. By default, only sessions with a status of `AVAILABLE` or `BUSY` are returned. You can filter the results by session status, compute target (cluster or serverless workgroup), or database. To retrieve the metadata for a single session, provide the `SessionId` parameter. Use `NextToken` to page through the session list.

Returns only the sessions that the caller created. When identity-enhanced role sessions are used, you must provide either the `ClusterIdentifier` or `WorkgroupName` parameter to ensure that the IAM Identity Center user can only access the Amazon Redshift IAM Identity Center applications they are assigned. For more information, see [ Trusted identity propagation overview](https://docs.aws.amazon.com/singlesignon/latest/userguide/trustedidentitypropagation-overview.html).

## Request Syntax
<a name="API_ListSessions_RequestSyntax"></a>

```
{
   "ClusterIdentifier": "{{string}}",
   "Database": "{{string}}",
   "MaxResults": {{number}},
   "NextToken": "{{string}}",
   "RoleLevel": {{boolean}},
   "SessionId": "{{string}}",
   "Status": "{{string}}",
   "WorkgroupName": "{{string}}"
}
```

## Request Parameters
<a name="API_ListSessions_RequestParameters"></a>

For information about the parameters that are common to all actions, see [Common Parameters](CommonParameters.md).

The request accepts the following data in JSON format.

**Note**  
In the following list, the required parameters are described first.

 ** [ClusterIdentifier](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-ClusterIdentifier"></a>
The cluster identifier. Only sessions on this cluster are returned. When providing `ClusterIdentifier`, then `WorkgroupName` can't be specified.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 63.  
Pattern: `[a-z][a-z0-9]*(-[a-z0-9]+)*`   
Required: No

 ** [Database](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-Database"></a>
The name of the database. Only sessions connected to this database are returned.  
Type: String  
Required: No

 ** [MaxResults](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-MaxResults"></a>
The maximum number of sessions to return in the response. If more sessions exist than fit in one response, the operation returns `NextToken` to paginate the results.  
Type: Integer  
Valid Range: Minimum value of 0. Maximum value of 100.  
Required: No

 ** [NextToken](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-NextToken"></a>
A value that indicates the starting point for the next set of response records in a subsequent request. If a value is returned in a response, you can retrieve the next set of records by providing this returned NextToken value in the next NextToken parameter and retrying the command. If the NextToken field is empty, all response records have been retrieved for the request.  
Type: String  
Required: No

 ** [RoleLevel](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-RoleLevel"></a>
Specifies whether to return all sessions created by the caller's IAM role, including sessions from previous IAM sessions. If false, only sessions created in the current IAM session are returned. The default is true.  
Type: Boolean  
Required: No

 ** [SessionId](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-SessionId"></a>
The identifier of a specific session to return metadata for. This value is a universally unique identifier (UUID) generated by Amazon Redshift Data API. When you provide `SessionId`, you can't specify `Status`, `ClusterIdentifier`, `WorkgroupName`, or `Database`.  
Type: String  
Pattern: `[a-z0-9]{8}(-[a-z0-9]{4}){3}-[a-z0-9]{12}(:\d{0,2})?`   
Required: No

 ** [Status](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-Status"></a>
The status of the sessions to list. If no status is specified, sessions with a status of `AVAILABLE` or `BUSY` are returned. Status values are defined as follows:  
+ AVAILABLE – The session is open and ready to run a SQL statement.
+ BUSY – The session is currently running a SQL statement.
+ CLOSED – The session is closed and can no longer run SQL statements.
Type: String  
Valid Values: `AVAILABLE | BUSY | CLOSED`   
Required: No

 ** [WorkgroupName](#API_ListSessions_RequestSyntax) **   <a name="redshiftdata-ListSessions-request-WorkgroupName"></a>
The serverless workgroup name or Amazon Resource Name (ARN). Only sessions on this workgroup are returned. When providing `WorkgroupName`, then `ClusterIdentifier` can't be specified.  
Type: String  
Length Constraints: Minimum length of 3. Maximum length of 128.  
Pattern: `([a-z0-9-]{3,63}|arn:(aws(-[a-z]+)*):redshift-serverless:([a-z]{2}(-gov|(-iso[a-z]?))?|eusc-[a-z]+)-[a-z]+-\d{1}:\d{12}:workgroup/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})`   
Required: No

## Response Syntax
<a name="API_ListSessions_ResponseSyntax"></a>

```
{
   "NextToken": "string",
   "Sessions": [ 
      { 
         "ClusterIdentifier": "string",
         "CreatedAt": number,
         "CurrentStatementId": "string",
         "Database": "string",
         "DbUser": "string",
         "SessionAliveSeconds": number,
         "SessionId": "string",
         "SessionTtl": number,
         "Status": "string",
         "UpdatedAt": number,
         "WorkgroupName": "string"
      }
   ]
}
```

## Response Elements
<a name="API_ListSessions_ResponseElements"></a>

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

 ** [Sessions](#API_ListSessions_ResponseSyntax) **   <a name="redshiftdata-ListSessions-response-Sessions"></a>
The sessions that match the request.  
Type: Array of [SessionData](API_SessionData.md) objects

 ** [NextToken](#API_ListSessions_ResponseSyntax) **   <a name="redshiftdata-ListSessions-response-NextToken"></a>
A value that indicates the starting point for the next set of response records in a subsequent request. If a value is returned in a response, you can retrieve the next set of records by providing this returned NextToken value in the next NextToken parameter and retrying the command. If the NextToken field is empty, all response records have been retrieved for the request.  
Type: String

## Errors
<a name="API_ListSessions_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

 ** InternalServerException **   
The Amazon Redshift Data API operation failed due to invalid input.     
 ** Message **   
The exception message.
HTTP Status Code: 500

 ** ResourceNotFoundException **   
The Amazon Redshift Data API operation failed due to a missing resource.     
 ** Message **   
The exception message.  
 ** ResourceId **   
Resource identifier associated with the exception.
HTTP Status Code: 400

 ** ValidationException **   
The Amazon Redshift Data API operation failed due to invalid input.     
 ** Message **   
The exception message.
HTTP Status Code: 400

## See Also
<a name="API_ListSessions_SeeAlso"></a>

For more information about using this API in one of the language-specific AWS SDKs, see the following:
+  [AWS Command Line Interface V2](https://docs.aws.amazon.com/goto/cli2/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for C\+\+](https://docs.aws.amazon.com/goto/SdkForCpp/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/redshift-data-2019-12-20/ListSessions) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/redshift-data-2019-12-20/ListSessions) 