How can I host multiple Ruby on Rails applications on a single database (DB) instance in AWS OpsWorks Stacks using Chef 11?

To host multiple Ruby on Rails applications on a single DB instance, you must prevent your applications from overwriting each other. Then, you map each application to the right application-specific domain.

Create a stack

  1. Open the OpsWorks Stacks console, and then choose Add your first stack.
  2. Choose Chef 11 stack.
  3. For Stack name, enter a name for your stack.
  4. Chose Add stack.

Add the Rails application server layer to your stack

  1. Open the OpsWorks Stacks console, and then choose the stack that you created.
  2. Choose Add a layer.
  3. On the OpsWorks view, for Rails stack, choose nginx and Unicorn.
  4. Choose Add layer.

Attach the database layer to your stack

  1. Create an RDS DB instance.
  2. Open the OpsWorks Stacks console, and then choose the stack that you created.
  3. Choose Add layer, and then choose the RDS view.
  4. To connect to your instance, enter your user name and password.
  5. Choose Register with Stack.

Create an instance for the Rails application server layer

  1. Open the OpsWorks Stacks console, and then choose the stack that you created.
  2. In the navigation pane, choose Instances, and then choose Add an instance.
  3. In the New view, for Hostname, enter a label of your choice.
  4. Choose Add Instance.
  5. Create two separate MySQL databases to use later for app1 and app2.

Add and deploy the first app

  1. Open the OpsWorks Stacks console, and then choose the stack that you created.
  2. In the navigation pane, choose Apps, and then choose Add an app.
  3. For Name, enter app1.
  4. For Document root, use the default root or enter a different root based on your needs.
  5. For Data source type, choose RDS.
  6. For Database instance, choose the database instance that you created earlier.
  7. For Database name, enter the name of the first database that you created.
  8. For Domain name, enter a domain name for app1.
  9. Choose Add app.
  10. Choose deploy.
  11. For Migrate database, choose Yes.
  12. Choose Deploy.

Add and deploy the second app

  1. Open the OpsWorks Stacks console, and then choose the stack that you created.
  2. In the navigation pane, choose Apps, and then choose Add an app.
  3. For Name, enter app2.
  4. For Document root, enter a document root that is different from the document root used for app1.
  5. For Data source type, choose RDS.
  6. For Database instance, choose the database instance that you created earlier.
    Note: You can run two databases on one database instance. Be sure to choose the relevant database name on the layer.
  7. For Database name, enter the name of the second database that you created.
  8. For Domain name, enter the name of a domain that you want to use for app2.
    Note: The domain for app2 must be different from the domain used for app1.
  9. Choose Add app.
  10. Choose deploy.
  11. For Migrate database, choose Yes.
  12. Choose Deploy.

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2019-02-12