我想在 Sagemaker Studio 中使用生命周期配置,以便在用户笔记本启动时运行给定的生命周期配置。
我的生命周期配置将具有 shell 脚本,该脚本将启动具有 python 脚本的 cronjob 以发送附加笔记本的运行持续时间。
#!/bin/bash
set -e
# PARAMETERS
IDLE_TIME=120
echo "Fetching the autostop script"
aws s3 cp s3://testing-west2/duration-check.py .
aws s3 cp s3://testing-west2/on-start.sh .
echo "Starting the SageMaker autostop script in cron"
(crontab -l 2>/dev/null; echo "*/1 * * * * /bin/bash -c '/usr/bin/python3 $DIR/duration-check.py --time ${IDLE_TIME} | tee -a /home/ec2-user/SageMaker/auto-stop-idle.log'") | crontab -
echo "Changing cloudwatch configuration"
cat $DIR/on-start.sh | sudo bash -s auto-stop-idle /home/ec2-user/SageMaker/auto-stop-idle.log