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
- Open the OpsWorks Stacks console, and then choose Add your first stack.
- Choose Chef 11 stack.
- For Stack name, enter a name for your stack.
- Chose Add stack.
Add the Rails application server layer to your stack
- Open the OpsWorks Stacks console, and then choose the stack that you created.
- Choose Add a layer.
- On the OpsWorks view, for Rails stack, choose nginx and Unicorn.
- Choose Add layer.
Attach the database layer to your stack
- Create an RDS DB instance.
- Open the OpsWorks Stacks console, and then choose the stack that you created.
- Choose Add layer, and then choose the RDS view.
- To connect to your instance, enter your user name and password.
- Choose Register with Stack.
Create an instance for the Rails application server layer
- Open the OpsWorks Stacks console, and then choose the stack that you created.
- In the navigation pane, choose Instances, and then choose Add an instance.
- In the New view, for Hostname, enter a label of your choice.
- Choose Add Instance.
- Create two separate MySQL databases to use later for app1 and app2.
Add and deploy the first app
- Open the OpsWorks Stacks console, and then choose the stack that you created.
- In the navigation pane, choose Apps, and then choose Add an app.
- For Name, enter app1.
- For Document root, use the default root or enter a different root based on your needs.
- For Data source type, choose RDS.
- For Database instance, choose the database instance that you created earlier.
- For Database name, enter the name of the first database that you created.
- For Domain name, enter a domain name for app1.
- Choose Add app.
- Choose deploy.
- For Migrate database, choose Yes.
- Choose Deploy.
Add and deploy the second app
- Open the OpsWorks Stacks console, and then choose the stack that you created.
- In the navigation pane, choose Apps, and then choose Add an app.
- For Name, enter app2.
- For Document root, enter a document root that is different from the document root used for app1.
- For Data source type, choose RDS.
- 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. - For Database name, enter the name of the second database that you created.
- 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. - Choose Add app.
- Choose deploy.
- For Migrate database, choose Yes.
- 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