How to create swap Memory in EC2 instance?

I have a low memory Ec2 instance, it is unable to build my nodejs project, It might be due to the lowe memory (RAM size) in the system,

Can anyone help me how to create a swap memory in my Ec2 instance.

Use the following sequence of commands, and add a line into '/etc/fstab' for startup config

sudo dd if=/dev/zero of=/swapfile bs=1M count=2000
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
swapon -s

Finally, add the following line into file 'sudo vi /etc/fstab'

/swapfile swap swap defaults 0 0
Log in to reply