aws-samples / sagemaker-studio-lifecycle-config-examples

MIT No Attribution
81 stars 53 forks source link

[New sample] S3 Browser extension install #18

Open athewsey opened 2 years ago

athewsey commented 2 years ago

The jupyterlab-s3-browser extension is useful for browsing Amazon S3 buckets and objects from within the SageMaker Studio UI - and was one of the tools specifically called out in the Studio JupyterLab v3 launch blog.

S3 Browser was originally drafted for inclusion alongside LSP-related features (also mentioned in the blog) in #14 - but review requested it be separated out. Raising this issue to track the ask.

The extension is not particularly challenging to install in JLv3 (pip install jupyterlab-s3-browser), but can cause pip to overwrite default installed botocore/aiobotocore versions which could have unintended, adverse consequences.

I've been working around that with a script something like:

# Since pip can sometimes fail to take all installed packages into account, we'll look up and
# specify the current botocore/boto3 versions to avoid pip breaking things:
BOTO3_VER=`pip show boto3 | grep 'Version:' | sed 's/Version: //'`
BOTOCORE_VER=`pip show botocore | grep 'Version:' | sed 's/Version: //'`

pip install jupyterlab-s3-browser \
    boto3==$BOTO3_VER \
    botocore==$BOTOCORE_VER

Was hoping to draft something quickly for this to work in both JLv3 and JLv1 (since early versions of the extension appear to pre-date even JLv2), but have been struggling to try and get the installation working properly on SMStudio JLv1.

tuliocasagrande commented 2 years ago

Hey @athewsey, thanks for the insights! I decided to just focus on v3 onwards.

Here's what worked for me:

#!/bin/bash

export AWS_SAGEMAKER_JUPYTERSERVER_IMAGE="${AWS_SAGEMAKER_JUPYTERSERVER_IMAGE:-'jupyter-server'}"
if [ "$AWS_SAGEMAKER_JUPYTERSERVER_IMAGE" != "jupyter-server-3" ] ; then
    echo "SageMaker version '$AWS_SAGEMAKER_JUPYTERSERVER_IMAGE' does not match 'jupyter-server-3'"
    exit 0
fi

# Activate the conda environment where Jupyter is installed:
eval "$(conda shell.bash hook)"
conda activate studio

# Since pip can sometimes fail to take all installed packages into account, we'll look up and
# specify the current botocore/boto3 versions to avoid pip breaking things:
BOTO3_VER=`pip show boto3 | grep 'Version:' | sed 's/Version: //'`
BOTOCORE_VER=`pip show botocore | grep 'Version:' | sed 's/Version: //'`

pip install jupyterlab-s3-browser \
    boto3==$BOTO3_VER \
    botocore==$BOTOCORE_VER
jupyter serverextension enable --py jupyterlab_s3_browser

conda deactivate