

# Idle shutdown
<a name="studio-updated-idle-shutdown"></a>

Amazon SageMaker AI supports shutting down idle resources to manage costs and prevent cost overruns due to cost accrued by idle, billable resources. It accomplishes this by detecting an app’s idle state and performing an app shutdown when idle criteria are met. 

SageMaker AI supports idle shutdown for the following applications. Idle shutdown must be set for each application type independently. 
+  JupyterLab 
+  Code Editor, based on Code-OSS, Visual Studio Code - Open Source 

 Idle shutdown can be set at either the domain or user profile level. When idle shutdown is set at the domain level, the idle shutdown settings apply to all applications created in the domain. When set at the user profile level, the idle shutdown settings apply only to the specific users that they are set for. User profile settings override domain settings.  

**Note**  
Idle shutdown requires the usage of the `SageMaker-distribution` (SMD) image with v2.0 or newer. Domains using an older SMD version can’t use the feature. These users must use an LCC to manage auto-shutdown instead. 

## Definition of idle
<a name="studio-updated-idle-shutdown-definition"></a>

 Idle shutdown settings only apply when the application becomes idle with no jobs running. SageMaker AI doesn’t start the idle shutdown timing until the instance becomes idle. The definition on idle differs based on whether the application type is JupyterLab or Code Editor. 

 For JupyterLab applications, the instance is considered idle when the following conditions are met: 
+  No active Jupyter kernel sessions 
+  No active Jupyter terminal sessions 

 For Code Editor applications, the instance is considered idle when the following conditions are met: 
+  No text file or notebook changes 
+  No files being viewed 
+  No interaction with the terminal

# Set up idle shutdown
<a name="studio-updated-idle-shutdown-setup"></a>

 The following sections show how to set up idle shutdown from either the console or using the AWS CLI. Idle shutdown can be set at either the domain or user profile level. 

## Prerequisites
<a name="studio-updated-idle-shutdown-setup-prereq"></a>

 To use idle shutdown with your application, you must complete the following prerequisites. 
+ Ensure that your application is using the SageMaker Distribution (SMD) version 2.0. You can select this version during application creation or update the image version of the application after creation. For more information, see [Update the SageMaker Distribution Image](studio-updated-jl-update-distribution-image.md) . 
+ For applications built with custom images, idle shutdown is supported if your custom image is created with SageMaker Distribution (SMD) version 2.0 or later as the base image. If the custom image is created with a different base image, then you must install the [jupyter-activity-monitor-extension >= 0.3.1](https://anaconda.org/conda-forge/jupyter-activity-monitor-extension) extension on the image and attach the image to your Amazon SageMaker AI domain for JupyterLab applications. For more information about custom images, see [Bring your own image (BYOI)](studio-updated-byoi.md).

## From the Console
<a name="studio-updated-idle-shutdown-setup-console"></a>

 The following sections show how to enable idle shutdown from the console. 

### Add when creating a new domain
<a name="studio-updated-idle-shutdown-setup-console-new-domain"></a>

1. Create a domain by following the steps in [Use custom setup for Amazon SageMaker AI](onboard-custom.md) 

1.  When configuring the application settings in the domain, navigate to either the Code Editor or JupyterLab section.  

1.  Select **Enable idle shutdown**. 

1.  Enter a default idle shutdown time in minutes. This values defaults to `10,080` if no value is entered. 

1.  (Optional) Select **Allow users to set custom idle shutdown time** to allow users to modify the idle shutdown time. 
   +  Enter a maximum value that users can set the default idle shutdown time to. You must enter a maximum value. The minimum value is set by Amazon SageMaker AI and must be `60`. 

### Add to an existing domain
<a name="studio-updated-idle-shutdown-setup-console-existing-domain"></a>

**Note**  
If idle shutdown is set when applications are running, they must be restarted for idle shutdown settings to take effect. 

1.  Navigate to the domain. 

1.  Choose the **App Configurations** tab. 

1.  From the **App Configurations** tab, navigate to either the Code Editor or JupyterLab section. 

1.  Select **Edit**. 

1.  Select **Enable idle shutdown**. 

1.  Enter a default idle shutdown time in minutes. This values defaults to `10,080` if no value is entered. 

1.  (Optional) Select **Allow users to set custom idle shutdown time** to allow users to modify the idle shutdown time. 
   +  Enter a maximum value that users can set the default idle shutdown time to. You must enter a maximum value. The minimum value is set by Amazon SageMaker AI and must be `60`. 

1.  Select **Submit**. 

### Add when creating a new user profile
<a name="studio-updated-idle-shutdown-setup-console-new-userprofile"></a>

1. Add a user profile by following the steps at [Add user profiles](domain-user-profile-add.md) 

1.  When configuring the application settings for the user profile, navigate to either the Code Editor or JupyterLab section. 

1.  Select **Enable idle shutdown**. 

1.  Enter a default idle shutdown time in minutes. This values defaults to `10,080` if no value is entered. 

1.  (Optional) Select **Allow users to set custom idle shutdown time** to allow users to modify the idle shutdown time. 
   +  Enter a maximum value that users can set the default idle shutdown time to. You must enter a maximum value. The minimum value is set by Amazon SageMaker AI and must be `60`. 

1.  Select “Save Changes”. 

### Add to an existing user profile
<a name="studio-updated-idle-shutdown-setup-console-existing-userprofile"></a>

 Note: If idle shutdown is set when applications are running, they must be restarted for idle shutdown settings to take effect. 

1.  Navigate to the user profile. 

1.  Choose the **App Configurations** tab. 

1.  From the ****App Configurations**** tab, navigate to either the Code Editor or JupyterLab section.  

1.  Select **Edit**. 

1.  Idle shutdown settings will show domain settings by default if configured for the domain. 

1.  Select **Enable idle shutdown**. 

1.  Enter a default idle shutdown time in minutes. This values defaults to `10,080` if no value is entered. 

1.  (Optional) Select **Allow users to set custom idle shutdown time** to allow users to modify the idle shutdown time. 
   +  Enter a maximum value that users can set the default idle shutdown time to. You must enter a maximum value. The minimum value is set by Amazon SageMaker AI and must be `60`. 

1.  Select **Save Changes**. 

## From the AWS CLI
<a name="studio-updated-idle-shutdown-setup-cli"></a>

 The following sections show how to enable idle shutdown using the AWS CLI. 

**Note**  
To enforce a specific timeout value from the AWS CLI, you must set `IdleTimeoutInMinutes`, `MaxIdleTimeoutInMinutes`, and `MinIdleTimeoutInMinutes` to the same value.

### Domain
<a name="studio-updated-idle-shutdown-setup-cli-domain"></a>

 The following command shows how to enable idle shutdown when updating an existing domain. To add idle shutdown for a new domain, use the `create-domain` command instead. 

**Note**  
If idle shutdown is set when applications are running, they must be restarted for idle shutdown settings to take effect. 

```
aws sagemaker update-domain --region region --domain-id domain-id \
--default-user-settings file://default-user-settings.json

## default-user-settings.json example for enforcing the default timeout
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120
        }
    }
}

## default-user-settings.json example for letting users customize the default timeout, between 2-5 hours
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 300
        }
    }
}
```

### User profile
<a name="studio-updated-idle-shutdown-setup-cli-userprofile"></a>

 The following command shows how to enable idle shutdown when updating an existing user profile. To add idle shutdown for a new user profile, use the `create-user-profile` command instead. 

**Note**  
If idle shutdown is set when applications are running, they must be restarted for idle shutdown settings to take effect. 

```
aws sagemaker update-user-profile --region region --domain-id domain-id \
--user-profile-name user-profile-name --user-settings file://user-settings.json

## user-settings.json example for enforcing the default timeout
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120
        }
    }
}

## user-settings.json example for letting users customize the default timeout, between 2-5 hours
{
    "JupyterLabAppSettings": {
        "AppLifecycleManagement": {
            "IdleSettings": {
                "LifecycleManagement": "ENABLED",
                "IdleTimeoutInMinutes": 120,
                "MinIdleTimeoutInMinutes": 120,
                "MaxIdleTimeoutInMinutes": 300
        }
    }
}
```

# Update default idle shutdown settings
<a name="studio-updated-idle-shutdown-update"></a>

 You can update the default idle shutdown settings at either the domain or user profile level. 

**Note**  
If idle shutdown is set when applications are running, they must be restarted for idle shutdown settings to take effect. 

## Update domain settings
<a name="studio-updated-idle-shutdown-update-domain"></a>

1.  Navigate to the domain. 

1.  Choose the **App Configurations** tab. 

1.  From the **App Configurations** tab, navigate to either the Code Editor or JupyterLab section.  

1.  In the section for the application that you want to modify the idle shutdown time limit for, select **Edit**. 

1.  Update the idle shutdown settings for the domain. 

1.  Select **Save Changes**. 

## Update user profile settings
<a name="studio-updated-idle-shutdown-update-userprofile"></a>

1.  Navigate to the domain. 

1.  Choose the **User profiles** tab. 

1.  From the **User profiles** tab, select the user profile to edit. 

1.  From the **User profile** page, choose the **Applications** tab. 

1.  On the **Applications** tab, navigate to either the Code Editor or JupyterLab section.  

1.  In the section for the application that you want to modify the idle shutdown time limit for, select **Edit**. 

1.  Update the idle shutdown settings for the user profile. 

1.  Select **Save Changes**. 

# Modify your idle shutdown time limit
<a name="studio-updated-idle-shutdown-modify"></a>

 Users may be able to modify the idle shutdown time limit if the admin gives access when adding support for idle shutdown. If support for idle shutdown is added, there may be a limit applied to the maximum time for idle shutdown. A user can set the value anywhere between the lower limit and upper limit. 

1.  Launch Amazon SageMaker Studio by following the steps in [Launch Amazon SageMaker Studio](studio-updated-launch.md). 

1.  From the **Applications** section, select the application type to update the idle shutdown time for. 

1.  Select the space to update. 

1.  Update **Idle shutdown (mins)** with your desired value. 
**Note**  
If idle shutdown is set when applications are running, they must be restarted for idle shutdown settings to take effect. 