If you have deployed your web application in Elastic Beanstalk in AWS and now you need to connect a database to this instance, and your database is actually residing in a different instance, how can you actually connect them?
It's easy with Elastic Beanstalk.
I will explain an example scenario that I used for connecting my elastic beanstalk web application with another instance containing my MongoDB database. By looking at this, you can customize as per your need. Don't worry. This is easy. :)
The only things you need here are the details about the
1. Database name that you need to connect to. Ex:- "myDB"
2. Port at which the database instance is listening. EX:- In the case of MongoDB, the listening port is 27017
3. Host name of your database instance. EX:- Like localhost, in this case, it will be the Public DNS of your database instance
4. The password of your database if exists.
First these details need to be set as environment variables in Elastic Beanstalk console.
Go to your environment in Elastic Beanstalk -> Configuration (In the left side bar) -> Software Configuration (One of the boxes) -> Click on the settings icon in that box
Under Environment Properties as shown in the figure above, set the 4 variable values as Environment Variables.
Now you can straight away access these environment properties from within your web application code. Replace the host, port, database name and password with these values accessed.
Cheers. :)
Comments
Post a Comment