.ebextensions/02_setup_swap.config
# taken from https://gist.github.com/steinnes/1f8a1b44fed4b136005f#gistcomment-1914616
commands:
create_pre_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/pre"
ignoreErrors: true
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/00_setup_swap.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
SWAPFILE=/var/swapfile
SWAP_MEGABYTES=2048
if [ -f $SWAPFILE ]; then
echo "Swapfile $SWAPFILE found, skipping"
exit 0;
fi
/bin/dd if=/dev/zero of=$SWAPFILE bs=1M count=$SWAP_MEGABYTES
/bin/chmod 600 $SWAPFILE
/sbin/mkswap $SWAPFILE
/sbin/swapon $SWAPFILE
exit 0;
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_remove_swap.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
SWAPFILE=/var/swapfile
/sbin/swapoff $SWAPFILE
rm $SWAPFILE
exit 0;