David Kimura PRO said about 3 years ago on Deploying to Amazon Linux 2 :
FYI to all, if you want to set up a swapfile, because you're using a small instance and not much RAM is available, you can create one when the VM is getting provisioned. I actually prefer to have a small swapfile in the event that my VM runs out of RAM, this would keep it from crashing. It is bad practice to rely on swap since it slows things down and is just overall bad practice, but it is much better than having the VM crash and die due to Out of Memory issues.

# .ebextensions/swap.config
commands:
  000_swap:
    ignoreErrors: true
    test: test ! -f /swapfile
    command: dd if=/dev/zero of=/swapfile bs=1M count=4096 && mkswap /swapfile && swapon /swapfile