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://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.
- James Hughes Mongo/Scala Quickstart – http://yobriefca.se/blog/2012/05/08/starter-for-10-scala/
- Amazon AWS – http://aws.amazon.com/
- Amazon EC2 Command line tools – http://aws.amazon.com/developertools/351
- Using VI to edit stuff while SSH’ed into instances for config editing – http://amath.colorado.edu/computing/unix/vi/
- Automate getting Public IPs – http://www.ducea.com/2009/06/01/howto-update-dns-hostnames-automatically-for-your-amazon-ec2-instances/