Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have created my RDS instance before creating my Elastic Beanstalk environment. The two are working together with no problem, but I'd like them to be linked together, and have the RDS parameters accessible via the RDS_* environment variables.

The Elastic Beanstalk configuration page says:

You do not have a database. You can create a new RDS database or use an existing database.

Although the first link creates a RDS instance in-place and links it to the current environment, the second link just redirects to this documentation page., which unfortunately only explains how to create a new RDS instance, but not how to link an existing one.

How can I associate an existing RDS instance to my Elastic Beanstalk environment?

share|improve this question

2 Answers 2

The above answer is correct but I wanted to add some extra data as I too had the same requirement and I suspect most people using EB and RDS should have the same requirement too even if they don't know it yet.

First, why would you want the RDS instance to exist outside the EB environment? So that the lifetime of the RDS instance is not tied to the lifetime of the EB environment. Everybody should be doing this, and it was recommended during the recent AWS re:invent event.

But as implied but not explicitly stated above, when you do it this way you do not get the RDS_* variables automatically populated and need to retrieve their values and populate them yourselves via web console or .ebextensions (the latter not recommended for security reasons).

But then, the next problem is if you want to programmatically create environments (such as for blue-green zero downtime deployments) then you need a solution for how to populate the sensitive RDS values, such as password. Unfortunately, this requires you to drop further down the AWS stack and use a CloudFormation template.

The ideal solution is an enhancement to EB so that the "use an existing database" link mentioned in the question actually lets you manually associate an existing RDS database and then have the RDS_* environment variables automatically populated again, rather than redirecting you to unhelpful documentation. AWS Support said this has been raised as a feature request but of course no timeframe given.

share|improve this answer
up vote 4 down vote accepted

Answer from the AWS support:

In order to associate an existing database to a EB Environment you have to take a snapshot of it via the Management Console and then choose "create a new RDS database" under the Data Layer. There does not appear to be a way to associate a running RDS instance to an existing EB Environment without launching a new one from a snapshot due to the way the RDS instance is tied into the Beanstalk environment's underlying Cloudformation stack. If you take a snapshot of your current RDS instance you can start it anew in EB if you wish.

If you want the RDS instance to exist outside of the environment you can simply provide the connection parameters as environment variables via the EB Console: Configuration -> Web Layer -> Software Configuration. Then, you can read the environment variable via PHP.

share|improve this answer
I took the second approach, defining environment variables with the RDS_* names to follow convention. The security groups are set pretty tight, but it still feels a little loose to put a DB password in an environment variable. –  velotron Jan 21 at 1:53
@velotron Same for me, but I got used to it! –  Benjamin Jan 21 at 11:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.