Last active
March 13, 2021 09:51
-
-
Save karahiyo/072423135a049b89e875ec99b5028960 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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