MeteorJS on Amazon Lightsail

Learning meteorjs can be overwhelming at first. Especially once you decide to host your applications, well, anywhere! According to the official meteorjs documentation, amazon aws is way too plebeian and you should obviously be using their overly expensive, in-home service: Galaxy!

Galaxy costs a staggering $30.00 USD/mo (not including the costs of staging a separate mongodb). Enter Amazon Lightsail! The server specs are limited but it will work well for small applications and it only costs $5.00/mo (including mongo!) Allow me to reveal the magic and demonstrate just how easy it is to host your meteor project! We’ll be using nginx, because I always have trouble binding anything to port 80 without some kind of wrapper. Plus I like the flexibility nginx gives.

Amazon Lightsail can be quickly setup. Go checkout their landing page and get the configuration pre-loaded with nginx. Amazon lightsail offers a nifty browser-based ssh tool. So let’s go ahead and use that to install some necessary packages.

sudo apt-get install npm mongodb
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

Next we need to configure nginx.

sudo nano /opt/bitnami/nginx/conf/bitnami/bitnami.conf

Let’s add a tried and true nginx proxy so meteor can be happy and nginx can be happy. Remove everything in location and make it look similar to this:

location / {
  proxy_pass http://localhost:3000/;
}

You will have to reload the nginx configuration for the changes to take effect.

sudo nginx -s reload

Your system is now setup. Back home, on your dev machine, you can generate a nodejs meteor “package” with this simple command. The output will contain a .tar.gz file.

meteor build ./output_dir

And once you have that tar.gz file, scp it up to your lightsail box. Here’s a little upgrade script I wrote which will extract the .tar.gz and set everything up according to the meteor README.

#!/bin/bash
FILE=$1
OUTPUT=$2
if [ ! -f $FILE ]; then
    echo "File not found!"
    exit 1
fi

echo "Upgrading meteor project"
tar -xzf $FILE --directory $OUTPUT

cd $OUTPUT
meteor npm install --save bcrypt
cd $OUTPUT/bundle/programs/server
sudo npm install

# Run the program
export PORT=3000
export MONGO_URL='mongodb://localhost:27017/meteor'
export ROOT_URL='http://127.0.0.1:3000/'
nodejs $OUTPUT/bundle/main.js

For my own project, I wrapped that latter part in an ubuntu service. But even without it… here’s a $5.00 meteorjs server!

Boom! mic drop