prepáč, že som stále nový bash skriptovanie. Mám okolo 10000 EC2 stupňa, ktoré som vytvoril tento bash skriptu zmeniť svoj EC2 stupňa typu, všetky inštancie názov a typ sú uložené v súbore. kód je práca, ale to trvá tak dlho spustiť cez stupňa stupňa.
niektorý majú vie, či môžem spustiť AWS Cli príkazov na všetky EC2 stupňa v jednom ísť ? Vďaka :)
#!/bin/bash
my_file='test.txt'
declare -a instanceID
declare -a fmo #Future Instance Size
while IFS=, read -r COL1 COL2; do
instanceID+=("$COL1")
fmo+=("$COL2")
done <"$my_file"
len=${#instanceID[@]}
for (( i=0; i < $len; i++)); do
vm_instance_id="${instanceID[$i]}"
vm_type="${fmo[$i]}"
echo Stoping $vm_instance_id
aws ec2 stop-instances --instance-ids $vm_instance_id
echo " Waiting for $vm_instance_id state to be STOP "
aws ec2 wait instance-stopped --instance-ids $vm_instance_id
echo Resizing $vm_instance_id to $vm_type
aws ec2 modify-instance-attribute --instance-id $vm_instance_id --instance-type $vm_type
echo Starting $vm_instance_id
aws ec2 start-instances --instance-ids $vm_instance_id
done