Search code examples
amazon-web-servicesamazon-sagemakeramazon-sagemaker-studio

How to enable autoshutdown lifecycle configuration in new Sagemaker Studio


Since AWS introduced the new Sagemaker Studio a couple of months ago, we want to start using it instead of Sagemaker Studio Classic.

Unfortunately, the lifecycle configuration script that we had in Studio Classic to automatically shut down the idle notebooks doesn't seem to be working in Studio. The Studio documentation only says that they recommend changing the LCC scripts and testing them, but not how.

How do I get the auto_shutdown script to work again? Or at least, how do I get an LCC to be executed correctly?

I tried to start from the ground up and check basic functionality with this simple script:

#!/bin/bash
set -eux
echo "Hello from new Studio"

I was expecting the space to launch and see the printed line in the CloudWatch logs.

However, attaching this as an LCC prevents spaces from running. There are no error messages, just a state of perpetual "updating test-space" notification. The run space button just shows a loading circle moving. CloudWatch logs don't show any information.

I'm deploying the domain through terraform (1.7.0 aws provider version 5.30) and add the LCC in the user profile user_settings block as jupyter_lab_app_settings. The studio_lifecycle_config_app_type is JupyterServer but it changing it to KernelGateway doesn't change anything. Once the domain is deployed, I go to my profile, create a test-space, click on it, and select the LCC script I just created.


Solution

  • Here's the script for automatically shutting down apps created using JupyterLab - https://github.com/aws-samples/sagemaker-studio-jupyterlab-lifecycle-config-examples/tree/main/scripts/auto-stop-idle

    While you can add the LCC in the user profile user_settings block as jupyter_lab_app_settings, you can also add them to the domain using the domain default settings, instead of setting them for each user (referring to this - default-user-settings)

    Lastly, the studio_lifecycle_config_app_type needs to be JupyterLab instead of JupyterServer, or KernelGateway (both are for Classic Studio applications).