Add EBS based swap to an EC2 instance

Add EBS Swap To AWS EC2 Instance
1. Create a new EBS volume of around 4-8GB and attach it to your instance.
We will assume the volume is /dev/xvdb
To check wether it is mounted use lsblk

2. If your volume is mounted, unmount it

sudo umount /dev/xvdb

3. Turn this volume into swap

sudo mkswap /dev/xvdb

4. Enable this volume as swap

sudo swapon /dev/xvdb

5. Make sure it is working as swap

swapon -s

6. Use this disk as swap if instance is restarted

sudo vim /etc/fstab

Add this:

/dev/xvdb       none    swap    sw  0       0

Add New EBS Volume to EC2 Instance

add-ebs-volume-to-ec2
A short, 3 step guide on how to add a new volume to your EC2 Instance.

Replace #### with your volume and #folder# with your folder path.

1. Format the disk

[ubuntu ~]$ sudo mkfs -t ext4 /dev/####

2. Mount the disk

[ubuntu ~]$ sudo mount /dev/#### #folder#

3. Auto-mount the volume on restart

[ubuntu ~]$ sudo vim /etc/fstab

fstab config

/dev/#### #folder# ext4 defaults 0 1