Skip to content

Commit f9c1b3e

Browse files
committed
Add ssm command
1 parent df36f68 commit f9c1b3e

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# Ref: https://catalog.us-east-1.prod.workshops.aws/workshops/2433d39e-ccfe-4c00-9d3d-9917b729258e/en-US/09-tips/01-ssm-login
4+
5+
usage(){
6+
echo ""
7+
echo "Usage: $0 <node_name>"
8+
echo ""
9+
echo "node_name - full or partial cluster node name to open ssm session into"
10+
echo ""
11+
}
12+
13+
if [ "$1" == "" ]; then
14+
usage
15+
else
16+
17+
# Get instance id
18+
node_id="$1"
19+
node_line=$(kubectl get nodes -L node.kubernetes.io/instance-type -L sagemaker.amazonaws.com/node-health-status -L sagemaker.amazonaws.com/deep-health-check-status | grep $node_id | head -n 1)
20+
node_name=$(echo $node_line | cut -d ' ' -f 1)
21+
node_type=$(echo $node_line | cut -d ' ' -f 6)
22+
instance_uid=$(echo $node_name | cut -d '-' -f 3)
23+
instance_id=$(echo i-${instance_uid})
24+
25+
# Get cluster id and instance group name
26+
pushd /hyperpod
27+
desc=$(./hyperpod-describe.sh | tail -n +5)
28+
cluster_id=$(echo $desc | jq -r .ClusterArn | cut -d '/' -f 2)
29+
popd
30+
instance_group_name=$(echo $desc | jq -r ".InstanceGroups[] | select(.InstanceType==\"$node_type\") | .InstanceGroupName")
31+
32+
echo ""
33+
echo "Instance ID: $instance_id"
34+
echo "Cluster ID: $cluster_id"
35+
echo "Instance Group Name: $instance_group_name"
36+
echo ""
37+
38+
# Construct and execute SSM command
39+
CMD="aws ssm start-session --target sagemaker-cluster:${cluster_id}_${instance_group_name}-${instance_id} --region $REGION"
40+
if [ ! "$VERBOSE" == "false" ]; then echo -e "\n${CMD}\n"; fi
41+
eval "$CMD"
42+
43+
fi

Container-Root/hyperpod/setup/eks/install-kubeps1.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ alias ne='node-exec.sh'
2020
alias ncn='node-cordon.sh'
2121
alias npd='node-pods-delete.sh'
2222
alias nsh='node-shell.sh'
23+
alias ssm='node-ssm.sh'
2324
alias nv='eks-node-viewer'
2425
alias tx='torchx'
2526
alias wkgp='watch-pods.sh'

Container-Root/hyperpod/setup/install-aws-cli.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ aws --version
2020
rm -rf ./aws
2121
rm -f awscliv2.zip
2222

23+
# Install Session Manager Plugin
24+
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb"
25+
sudo dpkg -i session-manager-plugin.deb
26+
rm -f session-manager-plugin.deb
2327

0 commit comments

Comments
 (0)