AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Customizing and Configuring a Ruby Environment

When deploying your Ruby application, you may want to customize and configure the behavior of your EC2 instances. You can easily customize your instances at the same time that you deploy your application version by including a configuration file with your source bundle. This section walks you through the process of creating a configuration file and bundling it with your source.

To customize and configure your Ruby environment

  1. Create a configuration file with the extension .config (e.g., myapp.config) and place it in an .ebextensions top-level directory of your source bundle. You can have multiple configuration files in your .ebextensions directory. For information about file format and contents of the configuration file, see Using Configuration Files.

    The following is an example snippet of a configuration file.

    # Configure third-party service credentials
    # in environment variables:
    option_settings:
      - option_name: AIRBRAKE_API_KEY
        value: MYAPIKEY
    
    # Run rake tasks before an application deployment
    container_commands:
      01deploy:
        command: rake my_deployment_tasks

    Note

    If you want to set environment variables that will be available to your application, you do not need to provide a "namespace" key in the option_settings section.

    You can also pass in your access credentials. For example, you could specify the following:

    # If you do not specify a namespace, the default used is aws:elasticbeanstalk:application:environment
    option_settings:
      - option_name: PARAM1
        value: somevalue
  2. Deploy your application version.

For an example walkthrough of deploying a Rails application, see Deploying a Rails Application to AWS Elastic Beanstalk. For an example walkthrough of deploying a Sinatra application, see Deploying a Sinatra Application to AWS Elastic Beanstalk.

Accessing Environment Variables

Inside the Ruby environment running in AWS Elastic Beanstalk, environment variables are accessible using ENV['VARIABLE_NAME'].

You might have a code snippet that looks similar to the following:

param1 = ENV['MYPARAM']
param2 = ENV['MYPARAM2']

For a list of option settings, see Ruby Container Options.