Skip to content

Latest commit

 

History

History
55 lines (30 loc) · 2.36 KB

auto-shutdown-instance.md

File metadata and controls

55 lines (30 loc) · 2.36 KB

Guide to implementing auto-shutdown features in virtual machines (EC2 or Sagemaker)

Autoshutdown EC2 instance

There already exists a great guide on how to configure autoshutdown on EC2. Just note that when you set the Alarm Thresholds, you may want to set the threshold percent to be higher than 2% to increase the sensitivity and make it easier for your machine to shut down.

Autoshudown Sagemaker instance

Configuring auto shutdown on Sagemaker instances is also relatively simple.

Configuring a new instance

  1. On the Sagemaker page, click Create notebook instance.

  1. Under Additional Configuration click the box under Lifecycle configuration - optional, then select Create a new lifecycle configuration.

  1. Name your configuration something like idle-shutdown-sagemaker and then paste in the following code under Start notebook. This code snippet will shutdown your VM after 3600 seconds (1 hr) of inactivity. If you want that time to be shorter, change it to something like 1800 (30 min).
#!/bin/bash

set -e

# PARAMETERS
IDLE_TIME=3600

echo "Fetching the autostop script"
wget https://raw.githubusercontent.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/master/scripts/auto-stop-idle/autostop.py

echo "Starting the SageMaker autostop script in cron"

(crontab -l 2>/dev/null; echo "*/5 * * * * /usr/bin/python $PWD/autostop.py --time $IDLE_TIME --ignore-connections") | crontab -

  1. Click Create configuration, then click Create notebook instance

Configuring an existing instance

The instructions for adding auto-shutdown to an existing instance are almost identical.

  1. Select the instance you want to modify, and click Edit in the top right. Your instance does need to be stopped.

  1. Now under Additional configuration select Lifecycle configuration - optional and follow the instructions above for 2–4.

  2. Restart your instance and confirm that it will shut down after the specified amount of time.