Just like:
aws ec2 describe-instances --filters "Name=tag:Name,Values=Test: Instance 1" --query 'Reservations[].Instances[].[InstanceId] --output text
lists the instances on aws. The following will show the public DNS names of the instances
aws ec2 describe-instances --filters "Name=tag:Name,Values=Test: Instance 1" --query 'Reservations[].Instances[].[PublicDnsName] --output text
If the instances are running with no public access, the following can be run for a list of private IP addresses:
aws ec2 describe-instances --filters "Name=tag:Name,Values=Test: Instance 1" --query 'Reservations[].Instances[].[PrivateIpAddress] --output text
The aws commands can then be used in a loop to process each entry:
for var in $(aws ec2 describe-instances --filters "Name=tag:Name,Values=Test: Instance 1" --query 'Reservations[].Instances[].[PrivateIpAddress] --output text)
do
ssh -i somekey.pem "ec2-user@$var" ......... # Loop through each IP address and run ssh
done
for var in $(aws ec2 describe-instances --filters "Name=tag:Name,Values=Test: Instance 1" --query 'Reservations[].Instances[].[InstanceId] --output text)
do
aws ec2 stop-instances --instance-ids "$var" # Loop through each instance id and stop.
done
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…