Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script to upgrade to SageMaker Python SDK v2 #53

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Lifecycle Configurations provide a mechanism to customize Notebook Instances via
* [publish-instance-metrics](scripts/publish-instance-metrics) - This script publishes the system-level metrics from the Notebook Instance to CloudWatch.
* [set-env-variable](scripts/set-env-variable) - This script gets a value from the Notebook Instance's tags and sets it as an environment variable for all processes including Jupyter.
* [set-git-config](scripts/set-git-config) - This script sets the username and email address in Git config.
* [upgrade-to-sagemaker-python-sdk-v2](scripts/upgrade-to-sagemaker-python-sdk-v2) - This script upgrades the SageMaker Python SDK to v2 in all Python 3 environments.

### Development

Expand Down
31 changes: 31 additions & 0 deletions scripts/upgrade-to-sagemaker-python-sdk-v2/on-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -e

# OVERVIEW
# This script upgrades the SageMaker Python SDK to v2 in all Python 3 environments.
#
# For more details, see https://sagemaker.readthedocs.io/en/stable/v2.html

sudo -u ec2-user -i <<'EOF'

for env in base /home/ec2-user/anaconda3/envs/*; do
source /home/ec2-user/anaconda3/bin/activate $(basename "$env")

py_version=$(python -c 'import sys; print(sys.version_info[0])')

ajaykarpur marked this conversation as resolved.
Show resolved Hide resolved
if [ $env == 'JupyterSystemEnv' ] || [ $py_version == 2 ]; then
echo "Skipping upgrade of the SageMaker Python SDK in $env."
continue
fi

echo "Upgrading the SageMaker Python SDK in $env..."

pip install --upgrade 'sagemaker>2'

echo "Upgraded the SageMaker Python SDK in $env."

source /home/ec2-user/anaconda3/bin/deactivate
done

EOF