David Kimura PRO said about 1 year ago on Deploying to Amazon Linux 2 :
  That is a pretty annoying error. You can enable Swap memory on the VM which will prevent things from crashing. This will create a 4GB Swapfile and enable it. 

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

Side note: People say that enabling Swap in production is horrible and bad practices. My take is that it's bad practice to have your app "randomly" crash and take down the site. Have proper monitoring in place for when you're approaching OOM and hitting swap and address the issues, but don't let the server crash.