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. With configuration files, the settings are applied every time you create a new 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
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
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.
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
trueto skip running
rake assets:precompileduring deployment.
RAILS_SKIP_MIGRATIONS – Set to
trueto skip running
rake db:migrateduring deployment.
RACK_ENV – Specify the environment stage for Rack. For example,
RAILS_ENV – Specify the environment stage for Rails. For example,
Inside the Ruby environment running in Elastic Beanstalk, environment variables are accessible using
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.
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.
option_settings: aws:elasticbeanstalk:application:environment: BUNDLE_WITHOUT: test RACK_ENV: development RAILS_ENV: development RAILS_SKIP_ASSET_COMPILIATION: true RAILS_SKIP_MIGRATIONS: true LOGGING: debug # Run shell commands during a deployment container_commands: 01deploy: command: rake my_deployment_tasks
Installing Packages with a Gemfile
Gemfile file in the root of your project source to use RubyGems
to install packages that your application requires.
Gemfile file is present, Elastic Beanstalk runs
install to install dependencies.