From 13f3cabd81e80b6ee6601a0adc1e520c8ebdf324 Mon Sep 17 00:00:00 2001 From: "daniel.carrillo" Date: Tue, 5 Nov 2019 12:05:16 +0100 Subject: [PATCH] [aws] Add alias for ssh through ssm proxy --- modules/aws/init.zsh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/aws/init.zsh b/modules/aws/init.zsh index 48822d1..18d589c 100644 --- a/modules/aws/init.zsh +++ b/modules/aws/init.zsh @@ -105,6 +105,18 @@ function aws_ssm_session_any { id=$(aws ec2 describe-instances --profile $profile --output text \ --filter "Name=tag-value,Values=$1" "Name=instance-state-name,Values=running" \ --query 'Reservations[0].Instances[0].InstanceId') - - aws ssm start-session --profile $profile --target $id + if [[ $2 == "ssh" ]]; then + AWS_PROFILE=$profile ssh $id + else + aws ssm start-session --profile $profile --target $id + fi +} + +# ~/.ssh/config +# +# Host i-* +# ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'" +# User +function ssh_aws_any { + aws_ssm_session_any $1 ssh }