AWS EC2 | increase/decrease RAM dynamically

It is not possible to dynamically adjust EC2 instance memory without changing instance type and stopping and starting the instance. To avoid running an instance idle you can start and stop it on a schedule using AWS Instance Schedule. Alternatively, you can run AWS Lambda on a schedule or on an event.


To expand on @AlexD's answer, Lambda is a good tool if you can have it perform the task you need to. Other options include using a Docker container running in ECS Fargate (which is also 'serverless'), or using a small EC2 instance with the CloudWatch Agent installed (to report memory usage) and setting up AutoScaling.