1010set -e
1111
1212INSTANCE_ID=" $1 "
13- SSH_AUTHORIZED_KEYS =" $2 "
13+ SSH_AUTHORIZED_KEYS_PATH =" $2 "
1414shift
1515shift
16+ PORT_FWD_ARGS=$*
17+
18+ echo " $( date -Iseconds) sm-connect-ssh-proxy: Connecting to: $INSTANCE_ID "
19+ echo " $( date -Iseconds) sm-connect-ssh-proxy: Extra args: $PORT_FWD_ARGS "
1620
1721instance_status=$( aws ssm describe-instance-information --filters Key=InstanceIds,Values=" $INSTANCE_ID " --query ' InstanceInformationList[0].PingStatus' --output text)
1822
2630# TODO: make it possible to override the default (also helps avoid race conditions)
2731SSH_KEY=~ /.ssh/sagemaker-ssh-gw
2832
29- echo " Generating $SSH_KEY keypair with ECDSA and uploading public key to $SSH_AUTHORIZED_KEYS "
33+ echo " Generating $SSH_KEY keypair with ECDSA and uploading public key to $SSH_AUTHORIZED_KEYS_PATH "
3034
3135echo ' yes' | ssh-keygen -t ecdsa -q -f " ${SSH_KEY} " -N ' ' > /dev/null
32- aws s3 cp " ${SSH_KEY} .pub" " ${SSH_AUTHORIZED_KEYS } "
36+ aws s3 cp " ${SSH_KEY} .pub" " ${SSH_AUTHORIZED_KEYS_PATH } "
3337
3438CURRENT_REGION=$( aws configure list | grep region | awk ' {print $2}' )
3539echo " Will use AWS Region: $CURRENT_REGION "
3640
37- PORT_FWD_ARGS=$*
38-
3941AWS_CLI_VERSION=$( aws --version)
4042echo " AWS CLI version (should be v2): $AWS_CLI_VERSION "
4143
@@ -50,7 +52,7 @@ send_command=$(aws ssm send-command \
5052 --timeout-seconds 30 \
5153 --parameters " commands=[
5254 'mkdir -p /etc/ssh/authorized_keys.d/',
53- 'aws s3 cp --recursive \" ${SSH_AUTHORIZED_KEYS } \" /etc/ssh/authorized_keys.d/',
55+ 'aws s3 cp --recursive \" ${SSH_AUTHORIZED_KEYS_PATH } \" /etc/ssh/authorized_keys.d/',
5456 'ls -la /etc/ssh/authorized_keys.d/',
5557 'cat /etc/ssh/authorized_keys.d/* > /etc/ssh/authorized_keys',
5658 'ls -la /etc/ssh/authorized_keys'
@@ -96,8 +98,7 @@ if [[ "$command_status" != "Success" ]]; then
9698 exit 2
9799fi
98100
99- echo " Connecting to $INSTANCE_ID with SSM and starting SSH port forwarding with the args: $PORT_FWD_ARGS "
100- # TODO: remove duplicating message from SSMProxy
101+ echo " $( date -Iseconds) sm-connect-ssh-proxy: Starting SSH over SSM proxy"
101102
102103# We don't use AWS-StartPortForwardingSession feature of SSM here, because we need port forwarding in both directions
103104# with -L and -R parameters of SSH. This is useful for forwarding the PyCharm license server, which needs -R option.
0 commit comments