Step1: Stop the Instance
aws ec2 stop-instances --instance-ids INSTANCEID
Step2: Change Instance type. I’ve used r5.xlarge in the below example.
aws ec2 modify-instance-attribute --instance-id INSTANCEID --instance-type "{\"Value\": \"r5.xlarge\"}"
Step3: Start the Instance
aws ec2 start-instances --instance-ids INSTANCEID