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 Family | Purpose | Characteristics |
| General Purpose | Balance of compute, memory, and networking resources | Versatile usage |
| Compute Optimized | Ideal for compute-intensive tasks | Higher performance for workloads like machine learning |
| Memory Optimized | Suitable for memory-intensive applications | High memory-to-vCPU ratio |
| Storage Optimized | Designed for workloads that require high, sequential read and write access | High 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
- 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".
- 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) tot2.large(8 GB RAM).
- Start the instance:
- Choose "Instance state" -> "Start instance" to boot with the new configuration.
What to check before and after the change
- Downtime: stopping and restarting the instance causes downtime, so schedule the change in a maintenance window if possible.
- Elastic IPs: an Elastic IP stays associated with the instance through a stop and start, but confirm the association after the restart.
- Cost: a type with more RAM will likely cost more. Estimate the impact with the AWS Pricing Calculator.
- 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.
- Security groups and key pairs: these stay intact, but verify that the instance is still accessible and secure.
- 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.
Related reading
- Adding AWS Lambda with VPC configuration causes timeout when accessing S3
- Adding multiple nodegroups to eks
- Adding type-hinting to functions that return boto3 objects?
- Adjusting Kubernetes configurations depending on environment
- Add swap memory with ansible
- Add trace and span id to Flink job
- Advantage of multiple pod on same node
- Aggregate logs by field value and plot as multiple series using AWS CloudWatch Insights
Course lessons on this
System design interview problems on this topic
- Design Dropbox: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough
- Design Youtube or Netflix: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.