Skip to content

Commit 2480b03

Browse files
SageMaker example script update (#517)
* Add IAM rights to CloudWatch logs * Add AWS CloudWatch logging * Remove parameter parsing logic * Add instruction comments to script * Update logging text * Update changelog * Revise LC, fix Docker run issue * revert version var name change --------- Co-authored-by: Michael Chin <[email protected]>
1 parent 685d9a1 commit 2480b03

File tree

4 files changed

+118
-19
lines changed

4 files changed

+118
-19
lines changed

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
- Requests executed in parallel for each label or class are now batched in
1313
groups of 10 to reduce chance of throttling errors
1414
(<https://github.com/aws/graph-explorer/pull/489>)
15+
- Updated the example SageMaker lifecycle configuration script and IAM policies
16+
to include logging to CloudWatch
17+
(<https://github.com/aws/graph-explorer/pull/517>)
1518

1619
**Bug Fixes and Minor Changes**
1720

additionaldocs/sagemaker/graph-explorer-neptune-analytics-policy.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
"Resource": [
1515
"arn:[AWS_PARTITION]:sagemaker:[AWS_REGION]:[AWS_ACCOUNT_ID]:notebook-instance/*"
1616
]
17+
},
18+
{
19+
"Sid": "LogGroupAccess",
20+
"Effect": "Allow",
21+
"Action": [
22+
"logs:CreateLogGroup",
23+
"logs:CreateLogStream",
24+
"logs:PutLogEvents"
25+
],
26+
"Resource": [
27+
"arn:[AWS_PARTITION]:logs:[AWS_REGION]:[AWS_ACCOUNT_ID]:log-group:/aws/sagemaker/*"
28+
]
1729
}
1830
]
1931
}

additionaldocs/sagemaker/graph-explorer-neptune-db-policy.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
"Resource": [
1515
"arn:[AWS_PARTITION]:sagemaker:[AWS_REGION]:[AWS_ACCOUNT_ID]:notebook-instance/*"
1616
]
17+
},
18+
{
19+
"Sid": "LogGroupAccess",
20+
"Effect": "Allow",
21+
"Action": [
22+
"logs:CreateLogGroup",
23+
"logs:CreateLogStream",
24+
"logs:PutLogEvents"
25+
],
26+
"Resource": [
27+
"arn:[AWS_PARTITION]:logs:[AWS_REGION]:[AWS_ACCOUNT_ID]:log-group:/aws/sagemaker/*"
28+
]
1729
}
1830
]
1931
}

additionaldocs/sagemaker/install-graph-explorer-lc.sh

Lines changed: 91 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,94 @@
22

33
sudo -u ec2-user -i <<'EOF'
44
5-
echo "export GRAPH_NOTEBOOK_AUTH_MODE=DEFAULT" >> ~/.bashrc # set to IAM instead of DEFAULT if cluster is IAM enabled
6-
echo "export GRAPH_NOTEBOOK_HOST=CHANGE-ME" >> ~/.bashrc
7-
echo "export GRAPH_NOTEBOOK_SERVICE=neptune-db" >> ~/.bashrc # set to `neptune-db` for Neptune database or `neptune-graph` for Neptune Analytics
8-
echo "export GRAPH_NOTEBOOK_PORT=8182" >> ~/.bashrc
9-
echo "export AWS_REGION=us-west-2" >> ~/.bashrc # modify region if needed
5+
echo "export GRAPH_NOTEBOOK_SERVICE=neptune-db" >> ~/.bashrc # Set to `neptune-graph` for Neptune Analytics.
6+
echo "export GRAPH_NOTEBOOK_HOST=CHANGE-ME" >> ~/.bashrc # Set to the endpoint of your Neptune instance
7+
echo "export GRAPH_NOTEBOOK_PORT=8182" >> ~/.bashrc # Set to the port of your Neptune instance
8+
echo "export GRAPH_NOTEBOOK_AUTH_MODE=IAM" >> ~/.bashrc # Set to `DEFAULT` if using DB cluster that is not IAM enabled. Leave as `IAM` for Neptune Analytics.
9+
echo "export AWS_REGION=us-west-2" >> ~/.bashrc # Set to AWS region of Neptune instance and notebook.
10+
echo "export NEPTUNE_LOAD_FROM_S3_ROLE_ARN=" >> ~/.bashrc # Sets IAM role for Neptune DB bulk loads via graph-notebook.
1011
1112
EXPLORER_VERSION=""
12-
for i in "$@"
13-
do
14-
case $i in
15-
-ev=*|--explorer-version=*)
16-
EXPLORER_VERSION="${i#*=}"
17-
echo "set explorer version to ${EXPLORER_VERSION}"
18-
shift
19-
;;
20-
esac
21-
done
13+
NOTEBOOK_VERSION=""
2214
2315
source activate JupyterSystemEnv
16+
17+
echo "installing Python 3 kernel"
18+
python3 -m ipykernel install --sys-prefix --name python3 --display-name "Python 3"
19+
20+
echo "installing python dependencies..."
21+
pip uninstall NeptuneGraphNotebook -y # legacy uninstall when we used to install from source in s3
22+
23+
pip install "jupyter_core<=5.3.2"
24+
pip install "jupyter_server<=2.7.3"
25+
pip install "jupyter-console<=6.4.0"
26+
pip install "jupyter-client<=6.1.12"
27+
pip install "ipywidgets==7.7.2"
28+
pip install "jupyterlab_widgets==1.1.1"
29+
pip install "notebook==6.4.12"
30+
pip install "nbclient<=0.7.0"
31+
pip install awswrangler
32+
33+
if [[ ${NOTEBOOK_VERSION} == "" ]]; then
34+
pip install --upgrade graph-notebook
35+
else
36+
pip install --upgrade graph-notebook==${NOTEBOOK_VERSION}
37+
fi
38+
39+
echo "installing nbextensions..."
40+
python -m graph_notebook.nbextensions.install
41+
42+
echo "installing static resources..."
43+
python -m graph_notebook.static_resources.install
44+
45+
echo "enabling visualization..."
46+
if [[ ${NOTEBOOK_VERSION//./} < 330 ]] && [[ ${NOTEBOOK_VERSION} != "" ]]; then
47+
jupyter nbextension install --py --sys-prefix graph_notebook.widgets
48+
fi
49+
jupyter nbextension enable --py --sys-prefix graph_notebook.widgets
50+
51+
mkdir -p ~/SageMaker/Neptune
52+
cd ~/SageMaker/Neptune || exit
53+
python -m graph_notebook.notebooks.install
54+
chmod -R a+rw ~/SageMaker/Neptune/*
55+
2456
source ~/.bashrc || exit
57+
HOST=${GRAPH_NOTEBOOK_HOST}
58+
PORT=${GRAPH_NOTEBOOK_PORT}
59+
SERVICE=${GRAPH_NOTEBOOK_SERVICE:-"neptune-db"}
60+
AUTH_MODE=${GRAPH_NOTEBOOK_AUTH_MODE}
61+
SSL=${GRAPH_NOTEBOOK_SSL}
62+
LOAD_FROM_S3_ARN=${NEPTUNE_LOAD_FROM_S3_ROLE_ARN}
63+
64+
if [[ ${SSL} -eq "" ]]; then
65+
SSL="True"
66+
fi
67+
68+
echo "Creating config with
69+
HOST: ${HOST}
70+
PORT: ${PORT}
71+
SERVICE: ${SERVICE}
72+
AUTH_MODE: ${AUTH_MODE}
73+
SSL: ${SSL}
74+
AWS_REGION: ${AWS_REGION}"
75+
76+
/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python -m graph_notebook.configuration.generate_config \
77+
--host "${HOST}" \
78+
--port "${PORT}" \
79+
--neptune_service "${SERVICE}" \
80+
--auth_mode "${AUTH_MODE}" \
81+
--ssl "${SSL}" \
82+
--load_from_s3_arn "${LOAD_FROM_S3_ARN}" \
83+
--aws_region "${AWS_REGION}"
84+
85+
echo "Adding graph_notebook.magics to ipython config..."
86+
if [[ ${NOTEBOOK_VERSION//./} > 341 ]] || [[ ${NOTEBOOK_VERSION} == "" ]]; then
87+
/home/ec2-user/anaconda3/envs/JupyterSystemEnv/bin/python -m graph_notebook.ipython_profile.configure_ipython_profile
88+
else
89+
echo "Skipping, unsupported on graph-notebook<=3.4.1"
90+
fi
91+
92+
echo "graph-notebook installation complete."
2593
2694
echo "Constructing explorer connection configuration..."
2795
@@ -44,9 +112,7 @@ else
44112
fi
45113
46114
NEPTUNE_URI="https://${GRAPH_NOTEBOOK_HOST}:${GRAPH_NOTEBOOK_PORT}"
47-
SERVICE=${GRAPH_NOTEBOOK_SERVICE:-"neptune-db"}
48115
AWS_REGION=${AWS_REGION}
49-
50116
echo "AUTH_MODE from Lifecycle: ${GRAPH_NOTEBOOK_AUTH_MODE}"
51117
if [[ ${GRAPH_NOTEBOOK_AUTH_MODE} == "IAM" ]]; then
52118
IAM=true
@@ -56,7 +122,6 @@ fi
56122
57123
echo "Explorer URI: ${EXPLORER_URI}"
58124
echo "Neptune URI: ${NEPTUNE_URI}"
59-
echo "Neptune Service: ${SERVICE}"
60125
echo "Explorer region: ${AWS_REGION}"
61126
echo "Explorer IAM auth mode: ${IAM}"
62127
@@ -81,6 +146,10 @@ fi
81146
echo "Using explorer image tag: ${EXPLORER_ECR_TAG}"
82147
83148
docker run -d -p 9250:9250 \
149+
--log-driver=awslogs \
150+
--log-opt awslogs-region=${AWS_REGION} \
151+
--log-opt awslogs-group=/aws/sagemaker/NotebookInstances \
152+
--log-opt awslogs-stream=${GRAPH_NOTEBOOK_NAME}/graph-explorer.log \
84153
--restart always \
85154
--env HOST=127.0.0.1 \
86155
--env PUBLIC_OR_PROXY_ENDPOINT=${EXPLORER_URI} \
@@ -90,11 +159,14 @@ docker run -d -p 9250:9250 \
90159
--env AWS_REGION=${AWS_REGION} \
91160
--env SERVICE_TYPE=${SERVICE} \
92161
--env PROXY_SERVER_HTTPS_CONNECTION=false \
93-
--env NEPTUNE_NOTEBOOK=true public.ecr.aws/neptune/graph-explorer:${EXPLORER_ECR_TAG}
162+
--env NEPTUNE_NOTEBOOK=true \
163+
--env LOG_LEVEL=debug \
164+
public.ecr.aws/neptune/graph-explorer:${EXPLORER_ECR_TAG}
94165
95166
echo "Explorer installation done."
96167
97168
conda /home/ec2-user/anaconda3/bin/deactivate
98169
echo "done."
99170
171+
100172
EOF

0 commit comments

Comments
 (0)