promiň, já jsem stále nový bash skriptování. Mám kolem 10000 EC2 instance, vytvořil jsem toto: bash script pro změnu můj EC2 instance typu, všechny instance název a typ jsou uloženy v souboru. kód je funkční, ale to trvá tak dlouho, spustit a to prostřednictvím například instanci.
má někdo ví, jestli jsem může běžet AWS Cli příkaz na všechny EC2 instance v jednom jít ? Díky :)
#!/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