Skip to content

Commit 9ee56ba

Browse files
#25 - fix sm-local-configure for Linux: using sudo
1 parent 3902607 commit 9ee56ba

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

kernel-lc-config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# A lifecycle configuration script for SageMaker Studio.
3+
# A lifecycle configuration script for SageMaker Studio kernel gateway.
44
# See SageMaker_SSH_IDE.ipynb for manual configuration and for explanation of commands.
55
# See https://docs.aws.amazon.com/sagemaker/latest/dg/studio-lcc.html .
66

sagemaker_ssh_helper/sm-helper-functions

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ function _is_macos() {
3939

4040
function _install_unzip() {
4141
if _is_centos; then
42-
yum install -y unzip
42+
sudo yum install -y unzip
4343
else
44-
apt-get install -y --no-install-recommends unzip
44+
sudo apt-get install -y --no-install-recommends unzip
4545
fi
4646
}
4747

4848
function _install_aws_cli_linux() {
4949
curl -sS "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"
5050
unzip -o -q -d /tmp/ /tmp/awscliv2.zip
51-
/tmp/aws/install --update
51+
sudo /tmp/aws/install --update
5252
}
5353

5454
function _install_aws_cli_macos() {
@@ -92,11 +92,11 @@ function _install_ssm_agent() {
9292
function _install_session_manager_plugin_ubuntu() {
9393
curl -sS "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" \
9494
-o "/tmp/session-manager-plugin.deb"
95-
dpkg -i /tmp/session-manager-plugin.deb
95+
sudo dpkg -i /tmp/session-manager-plugin.deb
9696
}
9797

9898
function _install_session_manager_plugin_centos() {
99-
yum install -y "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" \
99+
sudo yum install -y "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" \
100100
|| echo "Already installed?"
101101
}
102102

@@ -123,11 +123,11 @@ function _install_session_manager_plugin() {
123123

124124

125125
function _install_curl_ubuntu() {
126-
apt-get install -y --no-install-recommends curl
126+
sudo apt-get install -y --no-install-recommends curl
127127
}
128128

129129
function _install_curl_centos() {
130-
yum install -y curl
130+
sudo yum install -y curl
131131
}
132132

133133
function _install_curl() {
@@ -153,3 +153,14 @@ function _install_sudo() {
153153
apt-get install -y --no-install-recommends sudo
154154
fi
155155
}
156+
157+
function _install_noVNC_linux() {
158+
json_value_regexp='s/^[^"]*".*": \"\(.*\)\"[^"]*/\1/'
159+
latest_noVNC_release=$(curl -s https://api.github.com/repos/novnc/noVNC/releases/latest)
160+
161+
novnc_tag=$(echo "$latest_noVNC_release" | grep "tag_name" | sed -e "$json_value_regexp")
162+
echo "Got latest noVNC release tag: $novnc_tag"
163+
164+
curl -sSL "https://api.github.com/repos/novnc/noVNC/tarball/$novnc_tag" -o "/tmp/noVNC.tgz"
165+
tar xzf /tmp/noVNC.tgz --transform 's/^novnc-noVNC-[0-9a-f]\+/noVNC/'
166+
}

sagemaker_ssh_helper/sm-init-ssm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ _install_helper_scripts
1414

1515
set -e
1616

17+
_install_sudo
1718
_install_unzip
1819
_install_curl
1920
_install_aws_cli
@@ -78,5 +79,4 @@ aid=$(echo $response | jq --raw-output '.ActivationId')
7879
echo Yes | amazon-ssm-agent -register -id "$aid" -code "$acode" -region "$CURRENT_REGION"
7980

8081
# See https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-ssm-user-permissions.html
81-
_install_sudo
8282
echo "ssm-user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ssm-agent-users

sagemaker_ssh_helper/sm-local-configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ cat /etc/os-release || :
1313
python --version
1414

1515
# Install AWS CLI
16+
_install_unzip
17+
_install_curl
1618
_install_aws_cli
1719

1820
echo "AWS default region - $AWS_DEFAULT_REGION"

server-lc-config.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# A lifecycle configuration script for SageMaker Studio Jupyter Server.
4+
# Prepares environment to use port forwarding into kernel gateways
5+
# through Jupyter Server Proxy extension and noVNC.
6+
# See https://docs.aws.amazon.com/sagemaker/latest/dg/studio-lcc.html .
7+
8+
set -e
9+
10+
sudo yum install -y hostname
11+
hostname
12+
cat /opt/ml/metadata/resource-metadata.json
13+
14+
source /opt/conda/etc/profile.d/conda.sh
15+
conda activate base
16+
pip uninstall -y -q awscli
17+
pip install -q sagemaker-ssh-helper
18+
19+
# Uncomment two lines below to update SageMaker SSH Helper to the latest dev version from main branch
20+
#git clone https://github.com/aws-samples/sagemaker-ssh-helper.git
21+
#cd sagemaker-ssh-helper && pip install . && cd ..
22+
23+
ps xfaeww
24+
25+
which python
26+
which pip
27+
28+
env
29+
30+
sm-local-configure
31+
32+
_install_noVNC_linux
33+
34+
cd noVNC
35+
nohup ./utils/novnc_proxy --vnc 127.0.0.1:5901 &

0 commit comments

Comments
 (0)