Changing EC2 Instance Type
Learn how we can change the type of an EC2 instance.
We'll cover the following
This is a small but important lesson for the AWS SOA-CO2 exam. We can scale EC2 instances vertically by changing their type. Note that the EC2 instances need to be stopped before you change their size.
Practical
In the following widget, we’ll:
- Create a key pair.
- Create a security group and add an inbound rule to allow HTTP access over port 80.
- Fetch appropriate subnet and AMI IDs.
- Launch a
t2.micro
EC2 instance. The user data script automatically starts this instance with a web page. - Get the web page served by this instance.
- Stop the instance.
- Modify the instance type to
t2.nano
. - Get the web page served by the modified instance.
Points to note:
- The web page also shows the type of the EC2 instance and can be accessed from our web browser at http://[REPLACE-INSTANCE-PUBLIC-IP].
- The final web page on the
t2.nano
EC2 instance will still have the instance type ast2.micro
. This is because the user data script only runs when the instance is launched. The web page was made during the instance launch; therefore, its contents aren’t updated when the instance type is updated tot2.nano
. - Notice that the IP address of the instance changed when it was stopped and started.
Note: Please choose an AWS Region with the default VPC so the script can find a public subnet.
Get hands-on with 1400+ tech skills courses.