Amazon Lightsail VPS servers and AWS instances will usually crash when trying to create Let’s Encrypt certificates using certbot if there’s not enough memory.
There are two ways to fix this:
Upgrade to an Amazon Lightsail VPS or EC2 instance with 1GB of memory or more
Temporarily add swap space to your Amazon Lightsail VPS or EC2 instance
See my post on upgrading Amazon Lightsail VPS or follow the instructions below to add temporary swap space to your Lightsail server.
How to Add Temporary Swap Space to Amazon Lightsail VPS
Step 1 – Add the swap file
sudo dd if=/dev/zero of=/swapfile bs=1024 count=524288 sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile
Step 2 – Generate your certificates
sudo /opt/certbot/letsencrypt-auto certonly -c /etc/certbot/www.yourdomain.com.conf --renew-by-default
Step 3 – Remove the temporary swap space
sudo swapoff /swapfile sudo rm /swapfile
Step 4 – Add all of the above to your cron job
Edit your certbot cron job:
sudo pico /etc/cron.weekly/renew-ssl-certificates
It should look something like this:
dd if=/dev/zero of=/swapfile bs=1024 count=524288 chmod 600 /swapfile mkswap /swapfile swapon /swapfile /opt/certbot/letsencrypt-auto certonly -c /etc/certbot/www.yourdomain.com.conf --renew-by-default sudo swapoff /swapfile rm /swapfile service nginx restart
Your certbot and cron job commands will look different depending where you’re running them from and depending on the name and location of your configuration files.
If your Lightsail server has less than 1GB of memory then you should consider adding swap space permanently to your VPS, it will significantly increase stability.
Feel free to leave comments or questions below, and if you need help managing your Lightsail or AWS server then get in touch with me here, it’s one of the services I provide.
I hope you found this article helpful, and don’t forget to like my Facebook page.