aws-samples / amazon-sagemaker-notebook-instance-lifecycle-config-samples

A collection of sample scripts to customize Amazon SageMaker Notebook Instances using Lifecycle Configurations
MIT No Attribution
416 stars 248 forks source link

Adjusted script to work for both Amazon Linux 1 and Amazon Linux 2 notebook … #85

Closed andjsmi closed 2 years ago

andjsmi commented 2 years ago

Issue #, if available: 82

Description of changes: x flag added to the set command to increase verbosity in logs.

Script will test importing boto3 from /usr/bin/python which is successful for Amazon Linux 1 notebooks but fails for Amazon Linux 2 currently. If it fails (as expected on Amazon Linux 2) it will try again with /usr/bin/python3 (which has boto3 installed for both Amazon Linux 1 and Amazon Linux 2). If that fails it will exit with error. The cron task is set to use whichever is successful.

Python output from cron redirected to /var/log/jupyter.log. This makes the output from the script viewable in CloudWatch logs for the instance allowing for easier debugging.

Testing Done

# On Amazon Linux 1 notebook
/usr/bin/python -c "import boto3"
/usr/bin/python3 -c "import boto3"

# On Amazon Linux 2 notebook
/usr/bin/python -c "import boto3"
/usr/bin/python3 -c "import boto3"

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.