Running Rails on AWS: Know Your Options

Facebook
Twitter
LinkedIn

ChoicesIn this post, I’ll outline four basic options for running Rails on AWS and provide the details to help you decide which is best for your situation.

This is an overview of running Rails on EC2, Elastic Beanstalk, EC2 Container Service, and Engine Yard. More technical posts with code samples are coming next.

EC2, ELB, and RDS: For Linux Veterans

At the heart of AWS is Elastic Cloud Compute. EC2 instances are virtual machines of different sizes. You can choose an instance with resources as small as 1 vCPU and 0.5GB memory up to hundreds of vCPU and memory.

Linux and Windows EC2 instances are available. For running Rails, we’ll choose Linux EC2 instances. You can use different Linux distros so choose the one you are familiar with. A popular choice is Ubuntu. Amazon provides their own Amazon Linux.

While AWS, in general, can simplify your setup, using EC2 requires that you know how to set up a Linux server. You are getting a virtual machine after all, similar to other Cloud providers or hosting companies.

When booting EC2 instances, you start with an Amazon Machine Image (AMI). Amazon provides AMIs for different Linux distros. You can also choose third-party AMIs, free or paid, that can have pre-installed software for running Rails.

An EC2 instance has a root EBS volume. An Elastic Block Storage volume is separate from the instance but after you attach the volume to the instance, you can use it like any other physical hard drive. You can snapshot an EBS volume for backups. You can use the snapshot to create a new EBS volume which you can then use to create new EC2 instances.

An EBS volume can be anywhere from 1GB to 16TB. You pay per GB and you can resize your EBS volumes after creating them.

Most Rails applications use a database. Amazon Relational Database Service or RDS makes it easy to set up PostgreSQL, MySQL, and other relational databases. If you don’t have any custom requirements for your database, consider using RDS.

You can also install your database on an EC2 instance. You will have to manage backups and upgrades yourself if you choose this route.

When using multiple EC2 instances, you need an Elastic Load Balancer to distribute requests. AWS takes care of scaling the resources behind the scenes for the ELB to handle the load.

The EC2 instances, on the other hand, can scale either vertically or horizontally. For vertical scaling, you can change the instance size of an EC2 instance to give it more vCPU and memory. For horizontal scaling, you can add more EC2 instances of the same size. Both of these are done manually.

If you want AWS to add EC2 instances automatically, use an Auto Scaling group. You give it a load threshold and when the threshold is reached, AWS will boot EC2 instances for you. AWS will terminate instances if they are not needed.

You might also like:   The Ruby Unbundled Series: Services vs. Objects - The Battle for Decomposition and Reuse

For production, use an Auto Scaling group with at least 2 Rails EC2 instances for high availability. Use an ELB and use RDS for your database. For staging, it’s best to have the same setup. If you’re on a budget, you can use 1 EC2 instance and install Rails and a database on the same instance.

There’s a lot to learn to run Rails on AWS. If you don’t have any experience with AWS, the learning curve is steep. However, there are services that can help. We’ll talk about Elastic Beanstalk, ECS, and Engine Yard Cloud.

These 3 services create resources like EC2, Auto Scaling group, ELB, and EBS. You don’t need to create these individually which makes things easier for you.

AWS Elastic Beanstalk: For Linux Novices

In Elastic Beanstalk, you choose a software stack of an environment. In our case, we want a Ruby stack. We have a choice of either Puma or Passenger as the app server. We can choose the Ruby version from Ruby 1.9 to 2.3.

We can choose if we want to use an Auto Scaling group or if the environment has a single instance. We can also choose the size of the EBS root volume.

We provide our application code for Elastic Beanstalk to deploy. We create the application source bundle using zip or git archive. If we use the eb command line client of Elastic Beanstalk, it creates the application source bundle for us every time we deploy the app.

You can create the environment using the Elastic Beanstalk console or the eb command client. The eb client gives you a Ruby environment and deploys your app in a few commands.

Elastic Beanstalk is free. You only pay for the resources it creates like EC2 instances, EBS volumes, and ELB. Check out our full tutorial on Running Rails in AWS Elastic Beanstalk.

EC2 Container Service: For Containerized Rails Apps and Apps in Other Languages

Amazon ECS manages Docker containers on a cluster of EC2 instances. You create a task with the Docker image, CPU and memory of the container, the ports used by the container, etc. You also create a service with the desired number of tasks.

ECS schedules the containers on the cluster for you. It selects which EC2 instances will run which containers. ECS can create an ELB for your service.

You need a Docker image to use ECS. You can create one for your Rails app by following our article Using Docker for Rails in a Production Environment.

EC2 Container Service is free. You only pay for the resources it creates like EC2 instances, EBS volumes, and ELB.

You might also like:   Code Concurrency and Two Easy Fixes

Engine Yard: For 1-Click Speed and Customization

Engine Yard creates the EC2 instances, EBS volumes, and ELB load balancers for you. You provide us with the git URL of your Rails application and we’ll take care of everything.

We provision the AWS resources and install the software you need to run your Rails application. We have over 5 billion EC2 instance hours using our Ruby on Rails stack. You know things are done correctly and securely.

If you use a software not included in our default stack, we will customize your environment for you using Chef.

You deploy your app with a click of a button or using the ey command line client. With a single click or a single command, you can release a new version of your Rails app with zero downtime.

Engine Yard provides scalability and flexibility. You can go from 1 to 100 servers in a few clicks. You can set up disaster recovery in a second AWS region to make sure you’re always online.

We monitor your application 24/7. Our world-class Support team is ready to handle any problem any time of the day. You don’t have to be on-call again.

You get up to 50% lower AWS pricing than going direct. Support costs start at $25/month for Solo instances.

If you want to give Engine Yard a test run, get instant access to our 500 hour free trial.

Summary

Which one should you choose? It depends. Everything mentioned above has some learning curve. Sure you don’t need expertise on EC2, EBS, and ELB when using Elastic Beanstalk, EC2 Container Service, or Engine Yard. But you have to know how the services work. Aside from EC2, EBS, and ELB, you also need to know about applications, environments, tasks, services, etc.

  • If you have extensive Linux experience, you can go direct EC2.
  • If you are not familiar with setting up Linux servers, you can try Elastic Beanstalk.
  • If you have containerized your Rails application and have other apps written in other languages, you can try EC2 Container Service.
  • If you want to get your app up quickly and customize, you can try Engine Yard. Check out our free trial.

In my biased opinion, choose Engine Yard when deploying a Rails application in production. You get a Ruby on Rails stack that is widely used. We follow best practices in deploying Rails in AWS. You also get 24/7 support from AWS-certified Support Engineers. We also provide Platinum Support where we do everything for you — migrating your application, deploying your application, adding more instances, booting database replicas, everything.

This is just an overview of your options in running your Rails application in AWS. In future posts, we’ll take a more hands-on approach with these services so you can make a more informed decision.

Want more posts like this?

What you should do now:

Facebook
Twitter
LinkedIn

Easy Application Deployment to AWS

Focus on development, not on managing infrastructure

Deploying, running and managing your Ruby on Rails app is taking away precious resources? Engine Yard takes the operational overhead out of the equation, so you can keep innovating.

  • Fully-managed Ruby DevOps
  • Easy to use, Git Push deployment
  • Auto scaling, boost performance
  • Private, fully-configured Kubernetes cluster
  • Linear pricing that scales, no surprises
  • Decades of Ruby and AWS experience

14 day trial. No credit card required.

Sign Up for Engine Yard

14 day trial. No credit card required.

Book a Demo