What steps do I need to take before changing the instance type of my EC2 Linux instance?

5 minute read
1

My system requires more CPU or memory than is available on my current Amazon Elastic Compute Cloud (Amazon EC2) Linux instance. I want to know what steps I need to take before I change my instance type.

Short description

To optimize your Amazon EC2 Linux instance for your workload, change the instance type. Changing the instance type lets you modify the following configurations for your workload:

  • Number of CPU cores
  • Amount of RAM
  • Amount of assigned instance store space
  • Amazon Elastic Block Store (Amazon EBS) optimization
  • Enhanced networking
  • GPU cores
  • FPGAs
  • Machine learning accelerators

Note: It's a best practice to maintain backups of your instances and data. Before you change your infrastructure, create an AMI or create snapshots of your EBS volumes.

Resolution

Verify that your current instance type is compatible with the new instance type

Before you change instance types or instance families, verify that the current instance type and the new instance type are compatible. For a list of compatibility issues, see Compatibility for changing the instance type.

After you verify compatibility, you can change the instance type of your Amazon EBS-backed instance.

Stop your instance

Before you change instance types, you must stop your instance.

Important:

  • If your instance is instance store backed or has instance store volumes that contain data, then the data is lost when you stop the instance. If you're moving from one instance store-backed instance to another instance store-backed instance, then you must migrate the instance. For more information, see Change the instance type of an instance store-backed instance.
  • If your instance is part of an Amazon EC2 Auto Scaling group, then stopping the instance might terminate the instance. If you launched the instance with Amazon EMR, AWS CloudFormation, or AWS Elastic Beanstalk, then your instance might be part of an AWS Auto Scaling group. Instance termination in this scenario depends on the instance scale-in protection settings for your Auto Scaling group. If your instance is part of an Auto Scaling group, then temporarily remove the instance from the Auto Scaling group before starting the resolution steps.
  • If you're not using an Elastic IP address, then stopping and starting the instance changes the public IP address of your instance. It's a best practice to use an Elastic IP address instead of a public IP address when routing external traffic to your instance. If you're using Amazon Route 53, then you might have to update the Route 53 DNS records when the public IP changes.

Stop an instance using the Amazon EC2 console

  1. When you stop an instance, the data on any instance store volumes is erased. Before you stop an instance, verify that you've copied any data that you need from your instance store volumes to persistent storage, such as Amazon EBS or Amazon S3.

  2. Open the Amazon EC2 console.

  3. Select Instances, and then choose the instance.

  4. Choose Instance stateStop instance. If the Stop instance option isn't available, then the instance is already stopped or its root device is an instance store volume.

  5. When prompted for confirmation, choose Stop. It can take a few minutes for the instance to stop.

Stop an instance using a command line interface

You can use one of the following commands. For more information about these command line interfaces, see Access Amazon EC2.

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.

Enhanced networking

If you're converting to an instance that supports enhanced networking, then install any required drivers, and turn on enhanced networking on your current instance. For more information, see Enhanced networking on Linux.

Nitro-based instance types

If you're changing your instance to a Nitro-based instance type, then take the following actions:

  • Confirm that you installed the NVMe and ENA modules on your instance.
  • Check that any block devices that are listed in /etc/fstab are compatible with NVMe block device names (/dev/nvme1, /dev/nvme2, and so on).
  • Amazon EBS volumes are exposed as NVMe devices to these instance types, and the device names are changed on a stop or start event. To avoid volume mismatch, use the UUIDs or labels file system to mount the file systems.

To automate these checks, run the NitroInstanceChecks script. For more information, see Why is my Linux instance not booting after I changed its type to a Nitro-based instance type? Follow the instructions in the Run the NitroInstanceChecks script section.

After the script runs and you make necessary updates, verify that the DRIVERS entry in /etc/udev/rules.d/70-persistent-net.rules is set to ? or ENA.

Use a text editor to access the file. The following example uses the vi editor.

vi /etc/udev/rules.d/70-persistent-net.rules

The correct entry appears as follows:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="01:23:45:67:89:ab", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0

Networking on current generation instances

Current generation instances launch only in a virtual private cloud (VPC). If your current instance is an EC2-Classic instance, then migrate the instance to a Linux instance in a VPC.

Mixing EC2 architectures

If your instance's source AMI is built for a specific architecture, then you're restricted to creating instance types of the same architecture. Examples of AMIs that are built for specific architecture include 32-bit (i386), 64-bit (x86_64), or 64-bit ARM (arm64). This is also the case if your instance is running an AMI that's created for the mac1 instance type. You can't move these images between instance types.

Related information

Status checks for your instances

Amazon EC2 pricing

What do I need to do before migrating my EC2 instance to a sixth generation instance to make sure that I get maximum network performance?

AWS OFFICIAL
AWS OFFICIALUpdated a year ago