veken.io

Home

Setting up zer0bin on AWS

For my job I work on backend services. Thanks to our excellent ops department I rarely have to think about the cloud infrastructure. For me a database is the URL I use to connect to it. So to get a better understanding I wanted to setup a small service on AWS.

I decided to find a pastebin clone that I was able to selfhost. I chose zer0bin .

The plan was to create an EC2 instance to run zer0bin, and nginx. Zer0bin needs a database, for that I planned to use RDS. I used the AWS sandbox environment at work so I didn’t have to make my own account. Because of this I did run into a permission issue where I was not allowed to generate the key-pair for the EC2 instance. Once that was solved and the machine was online I tried to login with ssh but was unsuccessful. It turned out I needed to login with admin as the username, not ubuntu. Now that I had a shell let’s start.

First up, all the prerequisites. All of these instructions are taken from the zero0bin installation wiki or the respective projects installation instructions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# install nginx
sudo apt update
sudo apt instal nginx

# Install yarn
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt install nodejs
sudo corepack enable

# Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install git
sudo apt install git

Now we can start setting up zer0bin.

1
2
3
4
git clone https://github.com/zer0bin-dev/zer0bin
cd zer0bin
yarn
yarn run build

I setup a RDS and connected it to the EC2 instance. It’s at this point as I am writing this blog posts a couple months later from notes I took that I wish I had also taken screenshots of the AWS console. Next time.

Now we setup the database.

1
2
3
sudo apt install postgresql  # Needed for the psql client
createdb -h database-0bin.xxxxxxxxxxxx.eu-west-2.rds.amazonaws.com -p 5432 -U postgres -W 0bin
psql -h database-0bin.xxxxxxxxxxxx.eu-west-2.rds.amazonaws.com -p 5432 -U postgres -W -f schema.sql 0bin

Next step is to edit the config.json in the backend directory to point to the database.

From here my notes get let verbose because the problems keep coming. Another thing for next time, don’t slack on the note keeping. I’ll quickly summarize what I ran into.

To build the backend with cargo I had to fix permissions on the directory and install build-essential after that it was a simple cargo build --release.

Next was setting up certbot. Installing was done with pip. Installing the certs didn’t work. First I editing the nginx config but it still didn’t work. Turned out I needed to open port 80 and 433 on the EC2 machine. After that the certs generated but the https didn’t work yet. I had to mess around in the config and move the SSL parts around, and it started working!

The last thing I need to do is run the backend with ./target/release/zer0bin-bin from the backend directory.

What did I learn

In the future when doing these learning by doing projects I need to take better notes. I started of alright, but towards to end it was ~5 words per line. There should also be screenshots for the actions that happen in a browser.

I did get a small insight into how AWS works. But I have barely scratched the surface. I am going to find a course that will teach me more.