Change EC2 Instance Type Using AWS CLI

Tasks

  • Change the instance type from t2.micro to t2.nano for the nautilus-ec2 instance using aws-cli only.

  • Ensure the nautilus-ec2 instance is in the running state after the change.

Steps

  1. Get the instance ID and Stop the nautilus-ec2 instance:

     aws ec2 describe-instances --filters "Name=tag:Name,Values=nautilus-ec2" --query "Reservations[*].Instances[*].InstanceId" --output text
    • i-0a089a6cf430546c4

aws ec2 stop-instances --instance-ids i-0a089a6cf430546c4
  1. Wait until the instance is stopped:

aws ec2 wait instance-stopped --instance-ids i-0a089a6cf430546c4
  1. Change the instance type to t2.nano:

aws ec2 modify-instance-attribute --instance-id i-0a089a6cf430546c4 --instance-type "{\"Value\": \"t2.nano\"}"
  1. Start the nautilus-ec2 instance:

aws ec2 start-instances --instance-ids i-0a089a6cf430546c4
  1. Ensure the instance is in the running state:

     aws ec2 wait instance-running --instance-ids i-0a089a6cf430546c4
  2. Check the instance type now.

aws ec2 describe-instances --instance-ids i-0a089a6cf430546c4 --query "Reservations[*].Instances[*].InstanceType" --output text

#aws #cloudcomputing #happylearning