Skip to content

Instantly share code, notes, and snippets.

@karahiyo
Last active March 13, 2021 09:51
Show Gist options
  • Select an option

  • Save karahiyo/072423135a049b89e875ec99b5028960 to your computer and use it in GitHub Desktop.

Select an option

Save karahiyo/072423135a049b89e875ec99b5028960 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/fish
set aws_profile (
grep -E '\[profile .*\]' ~/.aws/config \
| gsed -e "s/\[profile \(.*\)\]/\1/g" \
| fzf
)
if test -z "$aws_profile"
exit 1
end
set target (
aws --profile $aws_profile ec2 describe-instances \
--filter "Name=instance-state-name,Values=running" | \
jq -c '.Reservations[].Instances[] |
{InstanceId, InstanceName: (.Tags[] | select(.Key=="Name").Value)}' \
| fzf
)
set target_instance_id (echo $target | jq -r '.InstanceId')
set target_instance_name (echo $target | jq -r '.InstanceName')
if test -z "$target_instance_id"
exit 1
end
echo Connecting to [$target_instance_name:$target_instance_id] ...
echo aws --profile $aws_profile ssm start-session --target $target_instance_id
aws --profile $aws_profile ssm start-session --target $target_instance_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment