How we can execute a Jupyter notebook python script automatically in Sagemaker?

Viewed 1732

I used terraform to create Sagemaker notebook instance and deploy Jupyter notebook python script to create and deploy a regression model.

I was able to run the scribe and create the model successfully via AWS console manually. However, I could not find a way to get it executed automatically. I even tried executing the script via shell commands through notebook instance’s lifecycle configuration. However, it did not work as expected. Any other idea please?

1 Answers

Figured this out. Passed the below script to notebook instance as lifecycle configuration.

#!/bin/sh
sudo -u ec2-user -i <<'EOF'
source activate python3
pip install runipy
nohup runipy <<path_to_the_jupyter_notebook>> &
source deactivate
EOF
Related