EC2 Instance and SWAP space

EC2 Instance and SWAP space

EC2 Instances on Amazon out of the box, does not contain any SWAP space . So if you exhaust memory, machine probably stuck. It’s very good practice, to give them at least slow SWAP memory to save instant crashes.

Process is quite simple. Let’s check how much free space we have:


Let’s make swapfile

sudo dd if=/dev/zero of=/var/swap bs=1M count=1024
sudo mkswap /var/swap
sudo chmod 0600 /var/swap
sudo swapon /var/swap

Safe changes to /etc/fstab

sudo echo "/var/swap none swap sw 0 0" >> /etc/fstab