How to Deploy Meteor 1.4 App to AWS EC2 in 2017

Philip Afful Nunoo
Feb 2, 2017 · 6 min read

This is a step by step guide on how to deploy a Meteor project to Amazon Web Services (AWS). This guide start from the basis with the assumption that one has already installed meteor on their system. With this said it is also thought that you have the latest version of node as well. As well as an AWS account.

AWS Setup

The AWS is barely straight forward. Follow the below steps to setup an instance for your application.

Within your console click on ec2

Select the EC2 option, and in the next screen choose “Launch Instance”.

Launch Instance

Upon choosing “Launch Instance”, your next view should display display a list of AMI (Amazon Machine Image). We would want to select ‘Ubuntu Server 16.04…’.

choose the server type

Now we are 50% almost done with the setup on AWS. You’d be moved to the below screen and asked to Choose your instance type. We’d stick with the default here and subsequent options. Move on to the next step by clicking on ‘Next: Configure Instance Detail’.

Select Instance Type

We are going to leave the default in the ‘Configure Instance Menu’ and skip the next step(ie. Add Storage) and move to ‘Configure Security Group’

Configure instance details

Configuring the security group of our instance remains one of the most important parts with the setup. Not only for Meteor but also with any application you’d want to host on EC2. We’d want to allow some specific traffic onto our website through either SSH, http or https. To add any new rule here, just click on the ‘Add Rule’ button. Next let’s start by adding the following rules

Rule 1: Type: SSH, Protocol: TCP, Port Range: 22, Source: My IP
Rule 2: Type: HTTP, Protocol: TCP, Port Range: 80, Source: Anywhere
Rule 3: Type: HTTPS, Protocol: TCP, Port Range: 443, Source: Anywhere

Add Security Rule

Your Security Group should end up looking like below. The first rule would allow you to ssh into your server, while the subsequent ones would allow users to see your site online.

Add Security Rules (SSH, HTTP, HTTPS)

You can go ahead by clicking ‘Review and Launch’ ones all is done.

Review Instance Launch

After viewing your current setting, you can go ahead to ‘Launch’ your app. You’d be showing a dialog as shown below where you’d be asked to select an instance pair.

Select Instance Pair Dialog

Since this is assuming we are working with a new app/project, let’s create a new pair. Give it a name, remember to Download the Key Pair and hit on the ‘Launch Instance’ button.

Create new key pair

The only thing we’d need now is the Public IP of our instance. And yes we are done.

Public Ip

Save this ip somewhere for later use. LOL.

Setting Up Meteor

As stated earlier on the assumption is that one has the latest node installed and also meteor as well. You can move over here and here to get this two done.

But before we continue let’s take a look at our pem file we download through the setup process and make sure we can ssh into our server.
Run the below command after navigating to where your .pem file is located.

$ chmod 400 your_pem_file_name.pem

This will allow ssh and mup(discuss more about this here) access to your pem file. You can now test to see if you can ssh into your server with the following command:

$ ssh -i /path/to/pem.pem ubuntu@public-ip-address

remember to replace ‘public-ip-address’ with your public ip from the last steps.

If you have successfully connected to your server, Congratulations! Now all you need to do is edit your mup.json file.

Create New Meteor App

An easy way I do this is to create a folder baring the name of the intended project, and creating the new meteor app in there. But since the emphasis is on how we can deploy let run through that side first.

$ meteor create app

We’d need to install a package called mup globally in our system by running

$ npm install mup -g

This would help up set configurations in mup and easily deploy our application to our instance on aws.

Within your project folder, not the meteor app folder, create a new folder named either app-deploy or .deploy. We’d go with the former in this

$ mkdir app-deploy && cd app-deploy

and run

$ mup init

This would initialize the empty directory with two files mup.js and settings.json.

With focus to the mup.js file. You should have something like this

module.exports = {
servers: {
one: {
host: '1.2.3.4',
username: 'root'
// pem:
// password:
// or leave blank for authenticate from ssh-agent
}
},
meteor: {
name: 'app',
path: '../app',
servers: {
one: {}
},
buildOptions: {
serverOnly: true,
},
env: {
ROOT_URL: 'app.com',
MONGO_URL: 'mongodb://localhost/meteor'
},
//dockerImage: 'kadirahq/meteord'
deployCheckWaitTime: 60
},
mongo: {
oplog: true,
port: 27017,
servers: {
one: {},
},
},
};

you can go ahead and replace the above with this, replacing the following appropriately:
<PATH_TO_YOUR_PEM_FILE>
<HOST_IP_FROM_YOUR_INSTANCE>
<PROJECT_OR_APP_NAME>
<PATH_TO_YOUR_METEOR_APP>
<DOMAIN_OR_ROOT_URL>
<DB_URL>

module.exports = {
servers: {
one: {
host: <HOST_IP_FROM_YOUR_INSTANCE>,
username: 'ubuntu',
pem: <PATH_TO_YOUR_PEM_FILE>
// pem:
// password:
// or leave blank for authenticate from ssh-agent
}
},
meteor: {
name: <PROJECT_OR_APP_NAME>,
path: <PATH_TO_YOUR_METEOR_APP>,
servers: {
one: {}
},
buildOptions: {
serverOnly: true,
},
env: {
ROOT_URL: <DOMAIN_OR_ROOT_URL>,
MONGO_URL: <DB_URL>
},
dockerImage: 'abernix/meteord:base',
deployCheckWaitTime: 60
},
mongo: {
oplog: true,
port: 27017,
servers: {
one: {},
},
},
};

Take note of this line as well, as we’re deploy for meteor 1.4. That’s the docker image has changed.

dockerImage: 'abernix/meteord:base',
deployCheckWaitTime: 60
},

Once your configuration has been done and fully setup, your can run the following two commands to setup and deploy your application

$ mup setup

This would setup your instance(or server)

$ mup deploy

This would build your app, upload and deploy your app onto your aws server.

You can access your site by visiting the public IP of the app.

In my next post I’d be writing on how to automate the deployment process on a CI tool. You can follow me to get update on that.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade