AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)

Using the AWS Elastic Beanstalk Ruby Platform

The AWS Elastic Beanstalk Ruby platform is a set of environment configurations for Ruby web applications that can run behind an nginx proxy server under a Puma or Passenger application server. Each configuration corresponds to a version of Ruby, including Ruby 1.9, Ruby 2.0, Ruby 2.1 and Ruby 2.2.

Elastic Beanstalk provides configuration options that you can use to customize the software that runs on the EC2 instances in your Elastic Beanstalk environment. You can configure environment variables needed by your application and enable log rotation to Amazon S3. The platform also predefines some common environment variables related to Rails and Rack for ease of discovery and use.

Platform-specific configuration options are available in the AWS Management Console for modifying the configuration of a running environment. To avoid losing your environment's configuration when you terminate it, you can use saved configurations to save your settings and later apply them to another environment.

To save settings in your source code, you can include configuration files. Settings in configuration files are applied every time you create an environment or deploy your application. You can also use configuration files to install packages, run scripts, and perform other instance customization operations during deployments.

If you use RubyGems, you can include a Gemfile file in your source bundle to install packages during deployment.

Settings applied in the AWS Management Console override the same settings in configuration files, if they exist. This lets you have default settings in configuration files, and override them with environment specific settings in the console. For more information about precedence, and other methods of changing settings, see Configuration Options.

Configuring Your Ruby Environment in the AWS Management Console

You can use the AWS Management Console to enable log rotation to Amazon S3 and configure variables that your application can read from the environment.

To access the software configuration settings for your environment

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management console for your environment.

  3. Choose Configuration.

  4. In the Software Configuration section, choose Edit.

Log Options

The Log Options section has two settings:

  • Instance profile– Specifies the instance profile that has permission to access the Amazon S3 bucket associated with your application.

  • Enable log file rotation to Amazon S3–Specifies whether log files for your application's Amazon EC2 instances should be copied to your Amazon S3 bucket associated with your application.

Environment Properties

The Environment Properties section lets you specify environment configuration settings on the Amazon EC2 instances that are running your application. Environment properties are passed in as key-value pairs to the application.

The Ruby platform defines the following properties for environment configuration:

  • BUNDLE_WITHOUT – A colon-separated list of groups to ignore when installing dependencies from a Gemfile.

  • RAILS_SKIP_ASSET_COMPILIATION – Set to true to skip running rake assets:precompile during deployment.

  • RAILS_SKIP_MIGRATIONS – Set to true to skip running rake db:migrate during deployment.

  • RACK_ENV – Specify the environment stage for Rack. For example, development, production, or test.

  • RAILS_ENV – Specify the environment stage for Rails. For example, development, production, or test.

Inside the Ruby environment running in Elastic Beanstalk, environment variables are accessible using the ENV object. For example, you could read a property named CONNECTION_STRING to a variable with the following code:

connectionstring = ENV['CONNECTION_STRING']

Environment configuration settings can contain any printable ASCII character except the grave accent (`, ASCII 96) and cannot exceed 200 characters in length.

Configuration Files

You can use a configuration file to set configuration options and perform other instance configuration tasks during deployments. The following configuration file sets each of the platform defined environment properties, sets an additional environment property named LOGGING, and runs a rake task with a container command during deployments.

Example .ebextensions/ruby-settings.config

    RACK_ENV: development
    RAILS_ENV: development
    LOGGING: debug

# Run shell commands during a deployment
    command: rake my_deployment_tasks

Installing Packages with a Gemfile

Use a Gemfile file in the root of your project source to use RubyGems to install packages that your application requires.

Example Gemfile

source ""
gem 'sinatra'
gem 'json'
gem 'rack-parser'

When a Gemfile file is present, Elastic Beanstalk runs bundle install to install dependencies.