Amazon EC2 – Mongo Play Scala Instance setup guide

EDIT: These instructions are now out of date as the SBT and Play dependences now need to be installed via the Typesafe Activator, see the Play Framework documentation for details.

This is a quick guide on how to create an EC2 instance with Mongo DB and Play/Scala, allowing you to quickly spin up a server and put your application online in half an hour or less. You can do all this with the AWS Free usage tier, so it costs nothing.

Chosen Play/Scala cause it’s what I’m working with now, but the same advantages apply to any other open source frameworks and dbs. Play/Scala is insanely easy and quick to use, see James Hughes great starter guide for info. All the info below was available online but not in one place or covering some of the tricks that held me up as a newbie.

1. Log into AWS EC2 and create Instance

– Ubuntu Server Instance (12.04 used for this example)

– Security group open SSH – 22, HTTP –  HTTPS – 443, TCP – 80 (add more if necessary), TCP – 28017 (mongo)

2. SSH into server (see AWS Management Console -> My Instances -> Instance Actions -> Connect, replace “root” user with “ubuntu” in connection string)

3. Install Mongo

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian-or-ubuntu-l…

http://amath.colorado.edu/computing/unix/vi/ – using vi to edit the list file

4. Install OpenJDK for Play/Scala (Play 2.0 requires JDK 6+)

http://www.wikihow.com/Install-Java-on-Linux – see “Ubuntu method using a Console”

5. Install SBT

– https://github.com/harrah/xsbt/wiki/Getting-Started-Setup (your play app will require sbt-launch.jar and an sbt script)

6. Install GIT (optional, but makes life much easier when retrieving/updating your app)

– sudo apt-get install git-core

– git clone https://USERNAME@github.com/USER/PROJECT.git (clone repo from git repo, will prompt for password)

– git pull (use later to get latest version)

7. Run SBT to download required libs and compile

– ./sbt (in project directory, it will download all scala/play libraries required, may take a while)

– start 80 (need to run as root to use port 80 or whatever port you want)

– Browse to ec2-999-999-999-999.compute-9.amazonaws.com:PORT to view your application (get AWS public dns from AWS EC2 console)


That’s it. At any point in the process you can create a snapshot of your image which you can use to generate a template image for future instances, so you don’t have to do the steps again.
You can also use the AWS command line tools to do all of the above by script, allowing you to spin up templated images, deploy latest code and start up applications, all completely automated. You can use this to build a full Dev/CI environment all with zero on site infrastructure.
Extra Links:
Advertisements

6 thoughts on “Amazon EC2 – Mongo Play Scala Instance setup guide

  1. If you want to be extra lean – you don’t need to install play or scala, provided you have sbt in your git repo it will resolve both dependencies for you.

  2. If I’m not wrong, if you have the latest version of type safe activator you can just have it installed and then run it. Since it gets SBT and Scala automatically you’ll be able to do this very easily.

  3. Thanks for the post. However, the link share for SBT installation is moved or another link which is there doesnot provide information how to install it on ubuntu amazon ec2 instance. I downloaded the package but not able to upload it on instance as scp or cp command not working.
    Error: Permission denied (publickey)
    How can I copy files and install SBT and run step 7.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s