33# Run a test against a SageMaker notebook
44# Only runs within the SDK's CI/CD environment
55
6+ function CreateLifeCycleConfig ()
7+ {
8+
9+ echo " Creating life cycle config...."
10+ LIFECYCLE_CONFIG_NAME=$1
11+ LIFECYCLE_CONFIG_CONTENT=$2
12+ aws sagemaker create-notebook-instance-lifecycle-config --notebook-instance-lifecycle-config-name " $LIFECYCLE_CONFIG_NAME " --on-create Content=" $LIFECYCLE_CONFIG_CONTENT "
13+
14+ }
15+
16+ function DeleteLifeCycleConfig ()
17+ {
18+
19+ echo " Deleting the existing life cycle config...."
20+ LIFECYCLE_CONFIG_NAME=$1
21+ aws sagemaker delete-notebook-instance-lifecycle-config --notebook-instance-lifecycle-config-name " $LIFECYCLE_CONFIG_NAME "
22+
23+ }
24+
25+
26+ function CreateLifeCycleConfigContent ()
27+ {
28+ ACCOUNT_ID=$1
29+ COMMIT_ID=$2
30+
31+ TARBALL_DIRECTORY=/tmp/sdk-tarballs
32+ LIFECYCLE_CONFIG_1=$( cat << 'EOF '
33+ #!/bin/bash
34+
35+ set -e
36+ set -x
37+
38+ mkdir "$HOME/.dlami"
39+ touch "$HOME/.dlami/dlami_build_in_progress"
40+ TARBALL_DIRECTORY=/tmp/sdk-tarballs
41+ mkdir -p "$TARBALL_DIRECTORY"
42+
43+ EOF
44+ )
45+
46+ LIFECYCLE_CONFIG_2=$( cat << EOF
47+
48+ aws s3 --region us-west-2 cp "s3://sagemaker-python-sdk-$ACCOUNT_ID /notebook_test/sagemaker-$COMMIT_ID .tar.gz" "$TARBALL_DIRECTORY /sagemaker.tar.gz"
49+
50+ EOF
51+ )
52+
53+ LIFECYCLE_CONFIG_3=$( cat << 'EOF '
54+
55+ # Include "base" separately since it's not a subdirectory.
56+ for env in base /home/ec2-user/anaconda3/envs/*; do
57+ echo "Updating SageMaker vended software in $env from pre-release SDKs..."
58+
59+ sudo -u ec2-user -E sh -c 'source /home/ec2-user/anaconda3/bin/activate "$env"'
60+
61+ echo "Updating SageMaker Python SDK..."
62+ pip install "$TARBALL_DIRECTORY/sagemaker.tar.gz"
63+
64+ sudo -u ec2-user -E sh -c 'source /home/ec2-user/anaconda3/bin/deactivate'
65+
66+ echo "Update of $env is complete."
67+ done
68+
69+ sudo rm -rf "$MODELS_SOURCE_DIRECTORY"
70+ sudo rm -rf "$TARBALL_DIRECTORY"
71+ rm -rf "$HOME/.dlami"
72+
73+ EOF
74+ )
75+
76+ LIFECYCLE_CONFIG_CONTENT=$(( echo "$LIFECYCLE_CONFIG_1$LIFECYCLE_CONFIG_2$LIFECYCLE_CONFIG_3 "|| echo "")| base64 )
77+
78+ echo "$LIFECYCLE_CONFIG_CONTENT "
79+
80+ }
81+
682set -euo pipefail
783
84+ ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
85+ COMMIT_ID=$(git rev-parse --short HEAD)
86+ LIFECYCLE_CONFIG_NAME="install-python-sdk-$COMMIT_ID "
87+
888python setup.py sdist
9- aws s3 --region us-west-2 cp ./dist/sagemaker-* .tar.gz s3://sagemaker-python-sdk-pr/sagemaker.tar.gz
10- aws s3 cp s3://sagemaker-mead-cli/mead-nb-test.tar.gz mead-nb-test.tar.gz
89+
90+ aws s3 --region us-west-2 cp ./dist/sagemaker-*.tar.gz s3 ://sagemaker-python-sdk-$ACCOUNT_ID /notebook_test/sagemaker-$COMMIT_ID .tar.gz
91+ aws s3 cp s3 ://sagemaker-python-sdk-cli-$ACCOUNT_ID /mead-nb-test.tar.gz mead-nb-test.tar.gz
1192tar -xzf mead-nb-test.tar.gz
12- git clone --depth 1 https://github.com/awslabs/amazon-sagemaker-examples.git
93+
94+
95+ LIFECYCLE_CONFIG_CONTENT=$(CreateLifeCycleConfigContent "$ACCOUNT_ID " "$COMMIT_ID " )
96+
97+ if !(CreateLifeCycleConfig "$LIFECYCLE_CONFIG_NAME " "$LIFECYCLE_CONFIG_CONTENT ") ; then
98+ (DeleteLifeCycleConfig "$LIFECYCLE_CONFIG_NAME ")
99+ (CreateLifeCycleConfig "$LIFECYCLE_CONFIG_NAME " "$LIFECYCLE_CONFIG_CONTENT ")
100+ fi
101+
102+ if [ -d amazon-sagemaker-examples ]; then rm -Rf amazon-sagemaker-examples; fi
103+ git clone --depth 1 https://github.com/aws/amazon-sagemaker-examples.git
104+
13105export JAVA_HOME=$(get-java-home)
14106echo "set JAVA_HOME=$JAVA_HOME "
15107export SAGEMAKER_ROLE_ARN=$(aws iam list-roles --output text --query "Roles[?RoleName == 'SageMakerRole'].Arn")
16108echo "set SAGEMAKER_ROLE_ARN=$SAGEMAKER_ROLE_ARN "
109+
17110./runtime/bin/mead-run-nb-test \
18111-- instance- type ml.c4 .8 xlarge \
19112-- region us- west- 2 \
20- --lifecycle-config-name install-python-sdk \
113+ -- lifecycle- config- name $LIFECYCLE_CONFIG_NAME \
21114-- notebook- instance- role- arn $SAGEMAKER_ROLE_ARN \
22115./amazon-sagemaker-examples/advanced_functionality/kmeans_bring_your_own_model/kmeans_bring_your_own_model.ipynb \
23116./amazon-sagemaker-examples/advanced_functionality/tensorflow_iris_byom/tensorflow_BYOM_iris.ipynb \
@@ -29,6 +122,7 @@ echo "set SAGEMAKER_ROLE_ARN=$SAGEMAKER_ROLE_ARN"
29122./amazon-sagemaker-examples/sagemaker-python-sdk/scikit_learn_randomforest/Sklearn_on_SageMaker_end2 end.ipynb \
30123./amazon-sagemaker-examples/sagemaker-python-sdk/tensorflow_moving_from_framework_mode_to_script_mode/tensorflow_moving_from_framework_mode_to_script_mode.ipynb \
31124./amazon-sagemaker-examples/sagemaker-python-sdk/tensorflow_script_mode_pipe_mode/tensorflow_script_mode_pipe_mode.ipynb \
32- ./amazon-sagemaker-examples/sagemaker-python-sdk/tensorflow_script_mode_quickstart/tensorflow_script_mode_quickstart.ipynb \
33125./amazon-sagemaker-examples/sagemaker-python-sdk/tensorflow_serving_using_elastic_inference_with_your_own_model/tensorflow_serving_pretrained_model_elastic_inference.ipynb \
34- ./amazon-sagemaker-examples/sagemaker-pipelines/tabular/abalone_build_train_deploy/sagemaker-pipelines-preprocess-train-evaluate-batch-transform.ipynb
126+ ./amazon-sagemaker-examples/sagemaker-pipelines/tabular/abalone_build_train_deploy/sagemaker-pipelines-preprocess-train-evaluate-batch-transform.ipynb
127+
128+ (DeleteLifeCycleConfig "$LIFECYCLE_CONFIG_NAME ")
0 commit comments