Rails Deployment on Heroku, Elastic Beanstalk, and IBM Bluemix (Cloud Foundry)

DZone 's Guide to

Rails Deployment on Heroku, Elastic Beanstalk, and IBM Bluemix (Cloud Foundry)

We take a comparative look at these three PaaS platforms to decide which is best for deploying and host web applications.

· Web Dev Zone ·
Free Resource

I recently wanted to prototype application deployment on a few PaaS platforms to see what would be best for a future startup. Ruby on Rails is my go-to language right now, so I wanted to test a Rails application on those platforms. I reviewed the Rails Tutorial codebase and it was a perfect fit for the test. I use this tutorial at CUE Marketplace to help new development team members learn the ropes. If you are new to Ruby, Rails, or want to see how to deploy a professional Rails application today, it’s a great resource and only takes a few hours to complete the entire course.

By default, the tutorial deploys the application to Heroku. I wanted to try it out on a couple others that have been on my radar for a while, AWS Elastic Beanstalk and Cloud Foundry (via IBM Bluemix). I’ll do a quick overview of each service, including features and pricing. I’ll then get into the details of the deployment.


Heroku was one of the first cloud platforms, founded in 2007. It was purchased by Salesforce in 2010. It was originally written as a platform for Ruby applications but has since added support for Node, Java, PHP, Python, Go, Scala, and Clojure. It has native support for Redis and Postgres and offers hundreds of other add-ons ranging from ClearDB MySQL database, Mandrill email delivery, New Relic for monitoring and everything else in between. The add-ons are basically simple integration points to those other services. Heroku has a free tier of pricing for sandbox apps that sleep most of the time. For hobby and smaller applications, they start at $7 per dyno per month and goes up to $25+ per dyno at the professional levels. The databases and most add-ons have free levels too and go up from there depending on usage. If there are fees involved with the add-ons, the fees will be added to your monthly Heroku bill, so it makes production operations billing a little simpler. You also have to pay $20 a month for use of SSL on your site not including the cost of your own SSL certificate. You can deploy your applications to either the United States or Europe.

Rails Deployment

  1. I created a free account on Heroku.
  2. I ensured Git was installed and I committed my project to the local master branch.
  3. I installed the CLI tool, Heroku Toolbelt.
  4. I ran heroku login and entered my Heroku account credentials.
  5. I ran heroku keys:add to add my local SSH key to Heroku.
  6. I ran heroku create to create the application on Heroku and to add the git remote for deployment.
  7. I’ ready for the initial deployment. I simply pushed the app to Heroku by running git push heroku master.
  8. My app uses the default PostgreSQL database, so I now need to migrate the DB by running heroku run rake db:migrate. Heroku will dynamically generate the database.yml file on deploy with the production settings.
  9. I ran heroku run rake db:seed to add the seed data.
  10. I used SendGrid for email delivery, so I had to run heroku addons:create sendgrid:starter. My application uses environment variables for the SendGrid credentials and Heroku added those variables for me automatically.

The application is ready to go! For subsequent releases I will run Step 7 and, to update the database, I will use Step 9.


Heroku is very simple to get going and to deploy changes. It is the default platform used in the Rails Tutorial project and I’ve used it in the past for my startups. It supports more languages and has more native and add-on services than any other platform, so everything you need to quickly get going is at your fingertips. Heroku is cheap to get started but gets more and more expensive as your application scales.

AWS Elastic Beanstalk

Amazon Web Services added Elastic Beanstalk (EB) to the AWS family in 2011. In addition to Ruby, it supports Java, .NET, PHP, Node, Python, Go, and recently added Docker support. It natively supports Amazon S3, RDS, DynamoDB, and SimpleDB. Amazon doesn’t give you any add-ons on top of that, but you can link to any of the services you need in your app separately and signup and add those to your app. EB pricing is easy. You only pay for the AWS resources that you use whether it be EC2, S3, RDS, or whatever. There are free tiers. The t2.nano EC2 level starts at about $5 per month for the US region. S3 pricing is super cheap too at 3 cents per GB. It supports SSL pretty easily with no additional cost other than your SSL certificate and it also has a nice auto-scaling feature that allows you to configure when to scale up or down the EC2 instances when the site traffic changes. You can deploy applications to the US, EU, APAC, and South American regions.

Rails Deployment

  1. I first created an Amazon AWS account.
  2. I made sure I had Git, Python, and Pip installed and I committed my project to the local master branch.
  3. I installed the EB CLI using the command sudo pip install awsebcli.
  4. I configured the EB CLI by running the command eb init. With this command, I selected, the region, added my AWS access ID and secret key, added the application name and selected the Ruby platform version. I’m using 2.2 on Puma. Puma was already set up in the Gemfile.
  5. We next deployed the application to EB with the command eb create rails-sampleapp-env.
  6. I added an AWS RDS PostgreSQL instance on the AWS EB management console.
  7. I had to make a few changes to the codebase. I had to manually edit the database.yml file to add the production settings for adapter, database, un, pw, host, and port.
adapter: pg
encoding: utf8
database: <%= ENV[‘RDS_DB_NAME’] %>
username: <%= ENV[‘RDS_USERNAME’] %>
password: <%= ENV[‘RDS_PASSWORD’] %>
host: <%= ENV[‘RDS_HOSTNAME’] %>
port: <%= ENV[‘RDS_PORT’] %>

8. I added the secret key base environment variable via the eb setenv SECRET_KEY_BASE=23098520lkjsdlkjfsdf command.

9. I signed up for a free version of SendGrid and I added the credentials via the eb setenv SENDGRID_USERNAME=your_un and eb setenv SENDGRID_PASSWORD=your_pw.

10. To get the seed data to run, I created the file .ebextensions/seeds.config with this in it

command: ‘export HOME=/root; rake db:seed’
leader_only: true

11. I committed to the master branch and then ran eb deploy to redeploy with changes above.


EB is a no-frills, simple platform for Rails. It supports all the big languages and containers and the easy addition of S3 and RDS was nice. The biggest plus here is that it is the least expensive. If you plan to eventually go to a self-managed EC2 deployment, it’s probably the easiest for future migration. Did I mention that it’s very inexpensive?

Cloud Foundry (via IBM Bluemix Instant Runtimes)

Cloud Foundry (CF) is an open source PaaS written by the folks at VMWare and released in 2011. VMWare spun it out into Pivotal in 2012. IBM uses the platform for its Bluemix Instant Runtimes. It supports Ruby, Java, Node, Go, PHP, and Python. Bluemix also supports Docker containers. Bluemix also integrates natively with Cloudant, Postgres and 15+ more native data and analytics services. It also has 100+ add-ons available for easy integration with a lot of overlap with Heroku. One really interesting add for Bluemix is the suite of Watson services. You can use services from speech to text, translation, document conversion, and, the very interesting, personality insights services. All have free levels with charges as usage increases. Bluemix pricing includes a free tier of up to 512mb worth of instances. It’s 24.15 per 512mb worth of instances from there. The pricing looks similar to the Heroku dyno pricing. You can deploy applications in the United States, Europe, and Austrailia.

Rails Deployment

  1. I created an account on IBM Bluemix.
  2. I ensured Git was installed and I committed my project to the local master branch.
  3. I installed the CF CLI.
  4. I ran the command cf api https://api.ng.bluemix.net.
  5. I then logged into Bluemix via cf login -u YOUR_USERNAME -o YOUR_ORG -s dev.
  6. I added the ClearDB database and SendGrid add-ons via the Bluemix web interface.
  7. I added the environment variables for S3, SendGrid, and secrets using the cf set-env APP_NAME ENV_VAR_NAME ENV_VAR_VALUE command.
  8. I updated the code to user msyql2 gem instead of pg.
  9. I made sure my app was committed to the local git repository.
  10. I then pushed the app to Bluemix and ran the migrate command via cf push sample-app -c ‘rake db:migrate & ‘ -i 1.
  11. I ran the seeds script via cf push sample-app -c ‘rake db:seeds & ‘ -i 1.
  12. I ran the app on Bluemix via cf push sample-app -c ‘bundle exec rails s -p $PORT’.


CF is an easy deployment just like the others. I wish that it auto-migrated the DB like EB. Bluemix has very similar offerings to Heroku, so I like the ease of deploying and the add-ons. The Cloundant DB is very nice. The biggest reason for me to pick Bluemix is the Watson APIs. There are some really nice services there and they are pretty cheap to get started. One other nice feature of Bluemix is the fact that they have the Cloud Foundry stuff along with Docker container support and just released OpenStack virtual machines. It offers many more deployment options than Heroku does. The overall pricing is similar to Heroku, so it’s generally cheap to get started and gets more and more expensive as you scale your app.

Final Thoughts

All three platforms above are great options for startups. Heroku has been around the longest and has the most add-ons. It’s just slightly easier to deploy and their documentation is solid. Elastic Beanstalk is least expensive and gives you the quickest path to eventual EC2 deployment. You don’t get any add-ons, so if you want email or queuing, you’ll have to signup for those services separately. EB is super cheap. IBM Bluemix is rock solid since Cloud Foundry has been around for a while. There are other services that use CF, so it would be easy for you to move to those. CF also gives you easy access to Watson. Not only are those services very cutting edge, you should get a marketing bump if you use them because of the name brand. Pricing for CF and Heroku are similar. They are cheap to get started and increase quickly as you scale your applications.

Have Fun!


To see more of what I'm working on at CUE Marketplace, click here.

rails ,heroku ,aws elastic beanstalk ,ibm bluemix ,web dev

Published at DZone with permission of Steve Jovanelly . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}