So you've been trying out RedwoodJS and are looking for some easy AWS hosting solution.
For that we will assume you have your repo with your RedwoodJS app ready to be deployed.
This short tutorial should set you on the right path, however I have not yet covered the
api side. Come back later, as I intend to explore this as well.
At the end of this tutorial you will get an instance of Lightsail up & running with the web side of your application's current version served to a public static IP and bound to your domain.
Let's get this thing started:
- Pick the Linux/Unix platform
- Select the Apps + OS blueprint category
- Tick the Node.js blueprint
Make sure your ssh key is configured properly as we are not going to cover that here. You can change this later though.
Select your instance plan, but be aware that you will need at least 1GB of RAM otherwise the deploy will fail to heap usage.
Name your instance and tag it if that's how you work.
Your instance is being created.
Go to the Lightsail > Networking tab and create a Static IP. Into the IP page, attach your newly created instance.
Copy the new IP, you will need it in a minute.
Disable IPv6 - this is not ideal but it will help you install a certificate later on with minimal effort.
If you don't have one, create a domain on AWS Route 53.
If you already have one, you will need to update the DNS of your domain provider to add the records.
Remove any IPv6 record from your domain's configuration that may be lingering - it would have to be an AAAA record.
Go to Route 53 > Hosted zones and select your domain.
Create a new Record of type 'A', leave its name empty and change its value to add the IP address you should still have in your clipboard - the static IP we created earlier in Lightsail.
Set the TTL at 60 if it is not already and save.
This solution doesn't feel ideal but getting it to work with Lightsail's DNS wasn't getting me anywhere. It is valid though and documented by AWS here
What happens next should happen in your instance, so please, SSH there now
In terminal use
ssh-keygen - passphrase is optional but recommended.
cat on the
[your_keyname_file].pub (hence on the
.pub) and add it to your Github settings. This will help your instance clone and update your app.
pm2 is necessary to deploy RedwoodJS baremetal and it is not included in the instance. That's going to be easy enough to fix, still in your
sudo npm install pm2 -g
You will use Bitnami's installed bncert tool, which will set you up with a Let's encrypt certificate in no time. The tool is preinstalled, so just run the following command. Make sure your domains are comma separated. We do not cover
www.[domain] in this tutorial so you are on your own for that.
$ sudo /opt/bitnami/bncert-tool --domains [domain1,domain2,...]
And follow on the instructions. It will install a certificate thanks to https://letsencrypt.org/fr/, so it's free.
Now we need to fix our Apache hosts to make sure they will serve your app.
In terminal, open the file and update the path of the app to add the suffix
$ vim /opt/bitnami/apache2/conf/bitnami/bitnami.conf
That's good. For port
:80, HTTP protocol.
You should report the same modification in here to support HTTPS:
$ sudo vim /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf
Save and restart apache:
$ sudo /opt/bitnami/ctlscript.sh restart apache
Please leave your instance now and go back to your local terminal, astutely positioned to your app's root directory. We should stay local as of now.
Enter the command:
yarn rw setup deploy baremetal
It should create you the following files:
Mine looks roughly like this:
host = "[static ip configured in Lightsail]"
username = "bitnami"
privateKeyPath = "[location to the default Lightsail SSH key file you would have configured while creating your Lightstail instance]"
agentForward = true
sides = ["api","web"]
packageManagerCommand = "yarn"
monitorCommand = "pm2"
path = "/home/bitnami/htdocs"
processNames = ["serve"]
repo = "[path to your git repo]"
branch = "main"
keepReleases = 5
That should do the trick.
repo should be updated accordingly.
title = "Redwood App"
- port = 8910
+ port = 80
Should be enough.
Now commit and push!
Back to terminal:
$ yarn rw deploy baremetal production --first-run
That's about it. Check your static IP, you should be good to go. If you just created your domain you're going to have to wait for a couple of days before you can check - AWS should notify you of its availability though and it can be way quicker.