# Lightsail : how to auto-renew SSL certificate ?

**URL:** <https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606>\
**Category:** AWS Networking\
**Tags:** load-balancer, lightsail\
**Created:** [April 10, 2020, 11:59pm UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606 "2020-04-10T23:59:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![payne007](https://awshq.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@payne007](https://awshq.com/u/payne007)\
**Post date:** [April 10, 2020, 11:59pm UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/1 "2020-04-10T23:59:34Z")

</div>

Referring to this piece of documentation: [https://lightsail.aws.amazon.com/ls/docs/en\_us/articles/amazon-lightsail-using-lets-encrypt-certificates-with-wordpress](https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-using-lets-encrypt-certificates-with-wordpress)

I do not need a Load Balancer, and thus don’t want to pay for one.

How do I get the SSL certificate to automatically renew itself ? I do not want to have to SSH every 2 months to repeat all these steps…

`certbot renew` apparently does the trick. But when I run it, it says that the certificate isn’t yet set to expire. This leads me to think that it’s a simple command that I’ll have to run every 2 months, rather than a command which takes care of running the appropriate set of commands automatically every 2 months.

**How do I get this process automatized ?**

* * *

**Related discussions:**

- [Optimizing costs?](https://awshq.com/t/optimizing-costs/20167)
- [Elb fallback on unhealthy targets](https://awshq.com/t/elb-fallback-on-unhealthy-targets/20724)
- [Lightsail instance shooting to 100% CPU usage, unresponsive until restarted](https://awshq.com/t/lightsail-instance-shooting-to-100-cpu-usage-unresponsive-until-restarted/15388)
- [ELI5: NLB vs ALB](https://awshq.com/t/eli5-nlb-vs-alb/10162)
- [Service to use for C2 server](https://awshq.com/t/service-to-use-for-c2-server/20496)

---

<div class="post-metadata">

**Author:** ![scrumptioushenry](https://awshq.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@scrumptioushenry](https://awshq.com/u/scrumptioushenry)\
**Post date:** [April 11, 2020, 1:34am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/2 "2020-04-11T01:34:39Z")

</div>

A cron script that runs once a month can do the renewal automatically.

The Bitnami Lightsail WP renew instructions are here in Step 5: Renew The Let’s Encrypt Certificate.[https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/](https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/)

It tries to renew once a month, shown by "0 0 1 \* \* " in the crontab file.

[https://crontab.guru/](https://crontab.guru/) is really helpful if you want to change that.

I generally write the crontab to a log file as well. I can post a sample if that would help.

Edit: or maybe just use the “Bitnami HTTPS Configuration Tool” if you’re able to! I haven’t tried it yet.

---

<div class="post-metadata">

**Author:** ![vm\_admin](https://awshq.com/letter_avatar_proxy/v4/letter/v/8e7dd6/32.png) [@vm\_admin](https://awshq.com/u/vm_admin)\
**Post date:** [April 11, 2020, 1:45am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/3 "2020-04-11T01:45:47Z")

</div>

Based off your link I am assuming you are using the Lightsail “WordPress” instance. Which is running Bitnami. Refer to bitnami documentation [https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/](https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/) bottom of the page has the guide to auto renew with cron job as above.

While you are there bitnami has great documentation and will pretty much have the answer to all of these type of questions.

---

<div class="post-metadata">

**Author:** ![LucidZulu](https://awshq.com/letter_avatar_proxy/v4/letter/l/3be4f8/32.png) [@LucidZulu](https://awshq.com/u/LucidZulu)\
**Post date:** [April 11, 2020, 3:17am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/4 "2020-04-11T03:17:47Z")

</div>

[https://www.multicastbits.com/guide-secure-unifi-cloud-controller-on-aws-lightsail-signed-with-lets-encrypt-ssl/#Set\_up\_Cronjob\_for\_SSL\_auto\_Renewal](https://www.multicastbits.com/guide-secure-unifi-cloud-controller-on-aws-lightsail-signed-with-lets-encrypt-ssl/#Set_up_Cronjob_for_SSL_auto_Renewal)

---

<div class="post-metadata">

**Author:** ![payne007](https://awshq.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@payne007](https://awshq.com/u/payne007)\
**Post date:** [April 11, 2020, 5:16am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/5 "2020-04-11T05:16:55Z")

</div>

> [@vm\_admin](#):
>
> Based off your link I am assuming you are using the Lightsail “WordPress” instance. Which is running Bitnami. Refer to bitnami documentation [https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/](https://docs.bitnami.com/aws/how-to/generate-install-lets-encrypt-ssl/) bottom …

Looks pretty solid. Thanks!

I’ve a feeling that using the cron job to run `certbot new` might be the same as using it to run the 3 lines of code they are proposing?

---

<div class="post-metadata">

**Author:** ![vm\_admin](https://awshq.com/letter_avatar_proxy/v4/letter/v/8e7dd6/32.png) [@vm\_admin](https://awshq.com/u/vm_admin)\
**Post date:** [April 11, 2020, 5:21am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/6 "2020-04-11T05:21:10Z")

</div>

> [@payne007](#):
>
> Looks pretty solid. Thanks! I’ve a feeling that using the cron job to run `certbot new` might be the same as using it to run the 3 lines of code they are proposing?

Yeah pretty much. Just this is using their own script.

---

<div class="post-metadata">

**Author:** ![payne007](https://awshq.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@payne007](https://awshq.com/u/payne007)\
**Post date:** [April 11, 2020, 5:22am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/7 "2020-04-11T05:22:18Z")

</div>

> [@vm\_admin](#):
>
> Yeah pretty much. Just this is using their own script.

Wonderful. Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![payne007](https://awshq.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@payne007](https://awshq.com/u/payne007)\
**Post date:** [April 13, 2020, 12:04am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/8 "2020-04-13T00:04:26Z")

</div>

> [@scrumptioushenry](#):
>
> A cron script that runs once a month can do the renewal automatically. The Bitnami Lightsail WP renew instructions are here in Step 5: Renew The Let’s Encrypt …

So, I’ve set up a cron through `crontab -e`, and selection “nano” as the editor.

Entered

0 0 1 \* \* /opt/bitnami/letsencrypt/scripts/renew-certificate.sh 2\> /dev/null

at the end of the file, saved (Ctrl+O), and exited (Ctrl+X).

I was prompted to choose the destination of the crontab, and I pressed enter for the default value, which pointed to a “tmp” folder. This is what made me think I hadn’t done it properly.

Typing `contrab -l` from within where I created “renew-certificate”, says there are no crontab.

---

<div class="post-metadata">

**Author:** ![scrumptioushenry](https://awshq.com/letter_avatar_proxy/v4/letter/s/f04885/32.png) [@scrumptioushenry](https://awshq.com/u/scrumptioushenry)\
**Post date:** [April 13, 2020, 1:50am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/9 "2020-04-13T01:50:03Z")

</div>

> [@payne007](#):
>
> So, I’ve set up a cron through `crontab -e`, and selection “nano” as the editor. Entered 0 0 1 \* \* /opt/bitnami/letsencrypt/scripts/renew-certificate.sh 2\> /dev/null at the end of the file, saved (Ctrl+O), and exited …

Not sure that its location matters (it varies by OS, but is often at /var/spool/cron/crontabs/root).

What happens when you type “sudo crontab -e”? Can you see the cron job? It will display a path at the top like it’s in a tmp file, but that’s not something you need to remember - it’s accessed by the “crontab -e” command, not the path.

To see if it’s working, add a log file, and change the cron runtime to something soon, like

`0 22 * 4 * /opt/bitnami/letsencrypt/scripts/renew-certificate.sh > /opt/bitnami/letsencrypt/logs/lego.log 2>&1`

(0 22 \* 4 \* = 11pm every day in April)

if /opt/bitnami/letsencrypt/logs doesn’t exist, you’ll need to add it:

`sudo mkdir /opt/bitnami/letsencrypt/logs`

After 11, check if there’s a log file, and if the script ran:

`cat /opt/bitnami/letsencrypt/logs/lego.log`

or maybe

`sudo cat /opt/bitnami/letsencrypt/logs/lego.log`

---

<div class="post-metadata">

**Author:** ![payne007](https://awshq.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@payne007](https://awshq.com/u/payne007)\
**Post date:** [April 24, 2020, 9:42pm UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/10 "2020-04-24T21:42:14Z")

</div>

> [@scrumptioushenry](#):
>
> Not sure that its location matters (it varies by OS, but is often at /var/spool/cron/crontabs/root). What happens when you type “sudo crontab -e”? Can you see the cron job? It will display a path at the top like it’s in …

Hey there, while we’re here: do you happen to know how I can bootstrap the LightSail instance ( **post-creation!** ) with the setup of the crontab?

I remember seeing bootstrapping options when initially setting up the instance, but now I can’t see where to edit that.

---

<div class="post-metadata">

**Author:** ![payne007](https://awshq.com/letter_avatar_proxy/v4/letter/p/48db29/32.png) [@payne007](https://awshq.com/u/payne007)\
**Post date:** [May 7, 2020, 5:13am UTC](https://awshq.com/t/lightsail-how-to-auto-renew-ssl-certificate/10606/11 "2020-05-07T05:13:54Z")

</div>

> [@scrumptioushenry](#):
>
> Not sure that its location matters (it varies by OS, but is often at /var/spool/cron/crontabs/root). What happens when you type “sudo crontab -e”? Can you see the cron job? It will display a path at the top like it’s in …

Finally got around to doing it. Thanks for your help! The suggested default location was indeed fine.
