Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.87 KB | None | 0 0
  1. #!/bin/bash
  2. if [ "$#" -ne 2 ]; then
  3.     echo "Illegal number of parameters! Pass the new instance type and instance id..."
  4. else
  5.  
  6. type=$1
  7. instance=$2
  8.  
  9. aws ec2 stop-instances --instance-ids $instance
  10. while [ "`aws ec2 describe-instances --instance-ids $instance --output text --query 'Reservations[*].Instances[*].State.Name'`" != "stopped" ]
  11. do
  12.  echo "Instance is stopping..."
  13.  sleep 1
  14. done
  15.  
  16. echo -e  "Instance is stopped \n Changing instance type..."
  17. aws ec2 modify-instance-attribute --instance-id $instance --instance-type "{\"Value\": \"$type\"}"
  18. sleep 4
  19. echo "Start the instance..."
  20. aws ec2 start-instances --instance-ids $instance
  21. while [ "`aws ec2 describe-instances --instance-ids $instance --output text --query 'Reservations[*].Instances[*].State.Name'`" != "running" ]
  22. do
  23.  echo "Instance is starting..."
  24.  sleep 1
  25. done
  26.  
  27. echo "Instance is started..."
  28. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement