11#! /bin/bash
22
33#  Commands:
4- #  connect <kernel_gateway_name> [--ssh-only]
4+ #  connect <kernel_gateway_name> [--ssh-only] [<extra_ssh_args>] 
55#  run-command <command> <args...>
6+ #  TODO: create <kernel_gateway_name> [--force-recreate] --domain <domain> --profile <profile> --image datascience-1.0 --instance ml.t3.medium  (use local user id)
7+ #  TODO: list
8+ #  TODO: open-firefox, open-chrome, open-safari
9+ #  TODO: set-kernel-gateway-name, get-kernel-gateway-name
610
711#  SageMaker Studio Kernel Gateway name is usually the same as the hostname,
812#  e. g. sagemaker-data-science-ml-m5-large-1234567890abcdef0
913
14+ #  To open SageMaker Studio UI in Firefox from command line on macOS, use the following command:
15+ #  open -a Firefox $(AWS_PROFILE=terry aws sagemaker create-presigned-domain-url --domain-id d-lnwlaexample --user-profile-name terry-whitlock --query AuthorizedUrl --output text)
16+ 
1017COMMAND=$1 
1118
1219if  [[ " $COMMAND " ==  " connect" ;  then 
1320
1421  SM_STUDIO_KGW_NAME=" $2 " 
1522  OPTIONS=" $3 " 
1623
24+   #  FIXME: distinguish between user profiles
25+ 
1726  INSTANCE_ID=$( python << EOF 
1827import sagemaker; from sagemaker_ssh_helper.manager import SSMManager; 
1928import logging; logging.basicConfig(level=logging.INFO); 
2029print(SSMManager().get_studio_kgw_instance_ids("$SM_STUDIO_KGW_NAME ", timeout_in_sec=300)[0]) 
2130EOF 
2231  )  
2332
33+   #  TODO: set-jb-license-server
34+   #  TODO: check that it's not started with 'http'
2435  #  replace with your JetBrains License Server host, or leave it as is if you don't use one
2536  JB_LICENSE_SERVER_HOST=" jetbrains-license-server.example.com" 
2637
3445
3546
3647  if  [[ " $OPTIONS " ==  " --ssh-only" ;  then 
48+     shift 
49+     shift 
50+     shift 
3751    sm-local-start-ssh " $INSTANCE_ID " 
38-         -L localhost:10022:localhost:22
52+         -L localhost:10022:localhost:22 \
53+         $* 
3954  else 
55+     shift 
56+     shift 
4057    sm-local-start-ssh " $INSTANCE_ID " 
4158        -L localhost:10022:localhost:22 \
4259        -L localhost:5901:localhost:5901 \
4360        -L localhost:8889:localhost:8889 \
44-         -R 127.0.0.1:443:" $JB_LICENSE_SERVER_HOST " 
61+         -R 127.0.0.1:443:" $JB_LICENSE_SERVER_HOST " 
62+         $* 
4563  fi 
4664
4765
@@ -51,7 +69,7 @@ elif [[ "$COMMAND" == "run-command" ]]; then
5169  ARGS=$* 
5270
5371  #  shellcheck disable=SC2086
54-   ssh -i ~ /.ssh/sagemaker-ssh-gw -p 10022 root@localhost \
72+   ssh -4 - i ~ /.ssh/sagemaker-ssh-gw -p 10022 root@localhost \
5573    -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
5674    $ARGS 
5775
0 commit comments