|
3 | 3 | # Commands: |
4 | 4 | # connect <kernel_gateway_name> [--ssh-only] [<extra_ssh_args>] |
5 | 5 | # run-command <command> <args...> |
6 | | -# TODO: create <kernel_gateway_name> [--recreate] --domain <domain> --user <profile-name> --image datascience-1.0 --instance ml.t3.medium |
| 6 | +# set-domain-id <domain_id> |
| 7 | +# set-user-profile-name <user_profile_name> |
| 8 | +# set-jb-license-server <jb-license-server-hostname-without-http> |
| 9 | +# TODO: create <kernel_gateway_name> [--recreate] --image datascience-1.0 --instance ml.t3.medium |
7 | 10 | # TODO: list (all apps from all users and domains marked with '*' if can connect with SSH and with '!' if user don't match) |
8 | | -# TODO: open-firefox <kernel_gateway_name> --domain <domain> --user <profile-name> |
9 | | -# TODO: set-domain, set-user (defaults) |
10 | | -# TODO: set-kernel-gateway-name, get-kernel-gateway-name (sets default for connect and create) |
11 | 11 |
|
12 | 12 | # SageMaker Studio Kernel Gateway name is usually the same as the hostname, |
13 | 13 | # e. g. sagemaker-data-science-ml-m5-large-1234567890abcdef0 |
14 | 14 |
|
15 | 15 | # To open SageMaker Studio UI in Firefox from command line on macOS, use the following command: |
16 | 16 | # 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) |
17 | 17 |
|
| 18 | +# replace with your JetBrains License Server host, or leave it as is if you don't use one |
| 19 | +JB_LICENSE_SERVER_HOST="jetbrains-license-server.example.com" |
| 20 | + |
| 21 | + |
18 | 22 | COMMAND=$1 |
19 | 23 |
|
20 | 24 | if [[ "$COMMAND" == "connect" ]]; then |
21 | 25 |
|
22 | 26 | SM_STUDIO_KGW_NAME="$2" |
23 | 27 | OPTIONS="$3" |
24 | 28 |
|
25 | | - # FIXME: distinguish between user profiles |
| 29 | + # TODO: if name is empty, list and choose |
| 30 | + |
| 31 | + DOMAIN_ID="" |
| 32 | + if [ -f ~/.sm-studio-domain-id ]; then |
| 33 | + DOMAIN_ID="$(cat ~/.sm-studio-domain-id)" |
| 34 | + else |
| 35 | + echo "sm-local-ssh-ide: WARNING: SageMaker Studio domain ID is not set, "\ |
| 36 | + "will attempt to connect to the latest active kernel gateway with name '$SM_STUDIO_KGW_NAME' in the region. "\ |
| 37 | + "Run 'sm-local-ssh-ide set-domain-id' to override." |
| 38 | + fi |
| 39 | + USER_PROFILE_NAME="" |
| 40 | + if [ -f ~/.sm-studio-user-profile-name ]; then |
| 41 | + USER_PROFILE_NAME="$(cat ~/.sm-studio-user-profile-name)" |
| 42 | + else |
| 43 | + echo "sm-local-ssh-ide: WARNING: SageMaker Studio user profile name is not set, "\ |
| 44 | + "will attempt to connect to the latest active kernel gateway with name '$SM_STUDIO_KGW_NAME' in the region. "\ |
| 45 | + "Run 'sm-local-ssh-ide set-user-profile-name' to override." |
| 46 | + fi |
26 | 47 |
|
27 | 48 | INSTANCE_ID=$(python <<EOF |
28 | 49 | import sagemaker; from sagemaker_ssh_helper.ide import SSHIDE; |
29 | 50 | import logging; logging.basicConfig(level=logging.INFO); |
30 | | -print(SSHIDE(None, None).get_kernel_instance_ids("$SM_STUDIO_KGW_NAME", timeout_in_sec=300)[0]) |
| 51 | +SSHIDE("$DOMAIN_ID", "$USER_PROFILE_NAME").print_kernel_instance_id("$SM_STUDIO_KGW_NAME", timeout_in_sec=300) |
31 | 52 | EOF |
32 | 53 | ) |
33 | 54 |
|
34 | | - # TODO: set-jb-license-server |
35 | | - # TODO: check that it's not started with 'http' |
36 | | - # replace with your JetBrains License Server host, or leave it as is if you don't use one |
37 | | - JB_LICENSE_SERVER_HOST="jetbrains-license-server.example.com" |
38 | | - |
39 | | - if [ -f ~/.sm-jb-license-server ]; then |
40 | | - echo "sm-local-ssh-ide: ~/.sm-jb-license-server file with PyCharm license server host is already configured, skipping override" |
41 | | - JB_LICENSE_SERVER_HOST="$(cat ~/.sm-jb-license-server)" |
42 | | - else |
43 | | - echo "sm-local-ssh-ide: Saving PyCharm License server host into ~/.sm-jb-license-server" |
44 | | - echo "$JB_LICENSE_SERVER_HOST" > ~/.sm-jb-license-server |
45 | | - fi |
46 | | - |
47 | | - |
48 | 55 | if [[ "$OPTIONS" == "--ssh-only" ]]; then |
| 56 | + echo "sm-local-ssh-ide: Connecting only SSH to local port 10022 (got the flag --ssh-only)" |
49 | 57 | shift |
50 | 58 | shift |
51 | 59 | shift |
|
55 | 63 | -L localhost:10022:localhost:22 \ |
56 | 64 | $* |
57 | 65 | else |
| 66 | + if [ -f ~/.sm-jb-license-server ]; then |
| 67 | + JB_LICENSE_SERVER_HOST="$(cat ~/.sm-jb-license-server)" |
| 68 | + fi |
| 69 | + |
| 70 | + echo "sm-local-ssh-ide: Connecting SSH, VNC and Jupyter to local ports 10022, 5901 and 8889 (add --ssh-only flag to override)" |
58 | 71 | shift |
59 | 72 | shift |
60 | 73 | sm-local-start-ssh "$INSTANCE_ID" \ |
|
65 | 78 | $* |
66 | 79 | fi |
67 | 80 |
|
| 81 | +elif [[ "$COMMAND" == "set-jb-license-server" ]]; then |
| 82 | + JB_LICENSE_SERVER_HOST="$2" |
| 83 | + |
| 84 | + echo "sm-local-ssh-ide: Saving PyCharm License server host into ~/.sm-jb-license-server" |
| 85 | + echo "$JB_LICENSE_SERVER_HOST" > ~/.sm-jb-license-server |
| 86 | + |
| 87 | +elif [[ "$COMMAND" == "set-domain-id" ]]; then |
| 88 | + DOMAIN_ID="$2" |
| 89 | + if [[ "$DOMAIN_ID" == "" ]]; then |
| 90 | + echo "sm-local-ssh-ide: ERROR: <domain-id> argument is expected" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + echo "sm-local-ssh-ide: Saving SageMaker Studio domain ID into ~/.sm-studio-domain-id" |
| 94 | + echo "$DOMAIN_ID" > ~/.sm-studio-domain-id |
| 95 | + |
| 96 | +elif [[ "$COMMAND" == "set-user-profile-name" ]]; then |
| 97 | + USER_PROFILE_NAME="$2" |
| 98 | + if [[ "$USER_PROFILE_NAME" == "" ]]; then |
| 99 | + echo "sm-local-ssh-ide: ERROR: <user-profile-name> argument is expected" |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | + echo "sm-local-ssh-ide: Saving SageMaker Studio user profile name into ~/.sm-studio-user-profile-name" |
| 103 | + echo "$USER_PROFILE_NAME" > ~/.sm-studio-user-profile-name |
68 | 104 |
|
69 | 105 | elif [[ "$COMMAND" == "run-command" ]]; then |
70 | 106 |
|
|
0 commit comments