AWS
EC2
RAM
Cloud Computing
Server Management

How to add RAM to an EC2 instance

Codemia Knowledge Hub ·

You can't add RAM to an existing EC2 instance directly. Memory comes with the instance type, so you stop the instance, change it to a type with more memory, and start it again.

Picking an instance type with more memory

Each instance type comes with a fixed amount of compute, memory and storage. Families range from general purpose to types optimized for compute, memory, storage or graphics:

Instance FamilyPurposeCharacteristics
General PurposeBalance of compute, memory, and networking resourcesVersatile usage
Compute OptimizedIdeal for compute-intensive tasksHigher performance for workloads like machine learning
Memory OptimizedSuitable for memory-intensive applicationsHigh memory-to-vCPU ratio
Storage OptimizedDesigned for workloads that require high, sequential read and write accessHigh IOPS and sequential throughput

If your application is memory-bound, a larger size in the same family or a memory optimized type is the usual answer.

Changing the instance type in the console

  1. Stop the instance:
    • Open the EC2 Dashboard in the AWS Management Console.
    • Select "Instances" in the sidebar.
    • Choose the instance and click "Instance state" -> "Stop instance".
  2. Change the instance type:
    • With the instance stopped, choose "Actions" -> "Instance settings" -> "Change instance type".
    • Select the new type. For example, move from t2.medium (4 GB RAM) to t2.large (8 GB RAM).
  3. Start the instance:
    • Choose "Instance state" -> "Start instance" to boot with the new configuration.

What to check before and after the change

  1. Downtime: stopping and restarting the instance causes downtime, so schedule the change in a maintenance window if possible.
  2. Elastic IPs: an Elastic IP stays associated with the instance through a stop and start, but confirm the association after the restart.
  3. Cost: a type with more RAM will likely cost more. Estimate the impact with the AWS Pricing Calculator.
  4. Elastic Beanstalk or Auto Scaling: if a fleet or an Elastic Beanstalk application manages the instance, make sure the new type is applied across all instances.
  5. Security groups and key pairs: these stay intact, but verify that the instance is still accessible and secure.
  6. Testing: test the application afterward to confirm you got the performance improvement you wanted.

Auto Scaling groups and CloudWatch

For heavily fluctuating workloads, Auto Scaling groups adjust the number of running instances based on policies you define, which may include instance type changes based on memory requirements.

Amazon CloudWatch can track memory utilization over time, which shows when a change is actually needed and helps avoid paying for over-provisioned instances.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design