amazon-web-servicesaws-lambdaamazon-cloudwatchamazon-sagemaker

Automatically "stop" Sagemaker notebook instance after inactivity?


I have a Sagemaker Jupyter notebook instance that I keep leaving online overnight by mistake, unnecessarily costing money...

Is there any way to automatically stop the Sagemaker notebook instance when there is no activity for say, 1 hour? Or would I have to make a custom script?


Solution

  • You can use Lifecycle configurations to set up an automatic job that will stop your instance after inactivity.

    There's a GitHub repository which has samples that you can use. In the repository, there's a auto-stop-idle script which will shutdown your instance once it's idle for more than 1 hour.

    What you need to do is

    1. to create a Lifecycle configuration using the script and
    2. associate the configuration with the instance. You can do this when you edit or create a Notebook instance.

    If you think 1 hour is too long you can tweak the script. This line has the value.