Deploying a Meteor 1.1 App on Amazon EC2 with a custom domain

Trinity
All About MeteorJS
Published in
4 min readJun 9, 2015

Most of the top Google searches were outdated / incomplete / assumed more knowledge than someone doing this for the first time would have. Will outline complete steps below so you don’t have to spend 3 hours and 3 faulty installations figuring it out too ☺ Also! All free! (Minus the custom domain but you don’t have to have use one.)

Preview: EC2, Elastic IP, and mup(meteor-up).

1. EC2

  • Log into your AWS account (or create one!) and select EC2 from the list of Amazon Web Services.
  • Click ‘Launch Instance’.
  • Choosing your AMI: I used Ubuntu 14.04 LTS(HVM) ami-5189a661.
  • Choose an instance type: I chose t2.micro because it’s free and with 1GB of memory was more than enough for my app. You can change these configurations as your app grows.
  • Configure Instance Details /Add Storage: Left these as is. Each option has a tooltip for additional info if you need to change any of these.
  • Tag Instance: Named my instance the same as the app.
  • Configure Security Group: “A security group is a set of firewall rules that control the traffic for your instance.” This allows you to add rules for who (what IP addresses) can access your instance and in what ways (SSH, HTTP, HTTPS, etc).

My first rule was only my IP could SSH into the instance. I forgot I was on a VPN so when I later turned it off and tried SSH’ing into it, it wasn’t working and it took me a few minutes to figure out why. I went back and changed the Security Group for that instance to include my “actual” IP.

My second rule was anyone(“Anywhere”) could access it over HTTP. I was deploying a read-only site; no users or real data to protect, your app might have different needs.

  • Review Instance Launch. If everything looks good, click to launch
  • You will be prompted to create a (or select an existing) key pair. This will allow you to securely SSH into your instance. Create one and download it (for example “pokedex_amzn_key”). Then move it wherever you keep the rest of your .pems. Standard practice is in a ~/.ssh folder.
  • “Your instances are now launched” woo!

2. Elastic IP

If you are not setting up a custom domain move onto 3.

  • In the left side nav under “Network & Security” select “Elastic IPs”.
  • Select to “Allocate New Address”. When you have a new IP address select it and click “Associate Address”. Then type in (or select) the name of your instance. If it doesn’t show up then it might still be initializing and you will have to wait a few seconds. Click associate. Now that IP belongs to your instance.
  • You will have to go to whichever hosting you are using and change the DNS record. Set the Elastic IP given to you by Amazon as the A record. Exact settings depend on how you want your url to work. For example I purchased pokede.xyz from Gandi for $2.50. I set my DNS so that both http://pokede.xyz/ and http://iamso.pokede.xyz/ loaded my site so my DNS record looked like this:
* 10800 IN A XX.XX.XX.XXX
@ 10800 IN A XX.XX.XX.XXX

As your host provider says it will take a few hours to fully propagate the changes.

3. Deploy!

After many tries SSH’ing into my instance and trying to install the correct versions of node/mongo and building the meteor app following outdated tutorials, I found Meteor Up and it only took a few minutes!

npm install -g mup
cd into_your_meteor_project
mup init

This creates a mup.json file (which you should add to your .gitignore!), and which you have to configure based on your settings, these were mine (tailor to your needs based on instructions in the mup repo):

{
"servers": [
{
"host": "XX.XX.XX.XXX" (Amazon IP or URL),
"username": "ubuntu",
"pem": "~/.ssh/pokedex_amzn_key.pem"
}
],

"setupMongo": true,
"setupNode": true,
"nodeVersion": "0.10.36",
"setupPhantom": true,
"enableUploadProgressBar": true,
"appName": "pokedex",
"app": "/path/to/pokedex",
"env": {
"PORT": 80,
"ROOT_URL": "http://pokede.xyz" (your site url),
"MONGO_URL": "mongodb://localhost:27017/pokedex(your_app_name)"
},

"deployCheckWaitTime": 15
}

Then!

mup setup
mup deploy

Go to your site url and check it out! (If you just updated the DNS record for your custom domain you may have to wait a few hours, but you can view your site by typing the Amazon IP directly into your browser.)

P.S. This is my first technical blog post! Would appreciate any feedback / comments / would be happy to answer your answerable questions ☺

--

--

Trinity
All About MeteorJS

software engineer, soon-to-be master of the universe (and hoping my @soylent will get me there)