Skip to content

Instantly share code, notes, and snippets.

@katzefudder
Last active July 14, 2021 08:52
Show Gist options
  • Save katzefudder/a43878b515442a8ae1d04b1a3ca2ca70 to your computer and use it in GitHub Desktop.
Save katzefudder/a43878b515442a8ae1d04b1a3ca2ca70 to your computer and use it in GitHub Desktop.
Open a terminal/ssh session on each ec2 instance available in your AWS region with this oneliner
#!/bin/bash
aws ec2 describe-instances --region eu-west-1 --filter Name=tag:Name,Values=InstanceName --query 'Reservations[].Instances[].PrivateIpAddress' --output text | xargs -I {} gnome-terminal -x ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/my_keys/my-private-key.pem -o IdentitiesOnly=yes cloud-user@{}
aws ec2 describe-instances --region eu-west-1 --output text --query 'Reservations[].Instances[].PublicIpAddress' | xargs -I {} osascript -e 'tell app "Terminal" to do script "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/my_keys/my-private-key.pem -o IdentitiesOnly=yes cloud-user@{}"'
aws ec2 describe-instances --region eu-west-1 --output text --query 'Reservations[].Instances[*].InstanceId' --filters Name=instance-state-name,Values=running | xargs -L 1 -I {} osascript -e 'tell app "Terminal" to do script "aws ssm start-session --target {}"'
@zimmdi
Copy link

zimmdi commented Jun 4, 2020

Maybe remove dependency to jq
aws ec2 describe-instances --region eu-west-1 --query "Reservations[].Instances[].PrivateIpAddress" --output text

@katzefudder
Copy link
Author

katzefudder commented Jun 4, 2020

nice catch, thanks!
jq removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment