désolé, je suis encore nouveau à l'écriture de scripts bash. J'ai autour de 10000 instance EC2, j'ai créé ce script bash pour changer mon instance EC2 type de nom de l'instance et le type sont stockées dans un fichier. le code fonctionne mais c'est si long à exécuter par exemple par exemple.
n'importe quel sait si je peux courir AWS commande Cli sur tous instance EC2 en une seule fois ? Merci :)
#!/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