amazon-rds – How to Associate an Existing RDS Instance to an Elastic Beanstalk Environment

amazon-rdselastic-beanstalk

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?

Best Answer

The "selected" answer is correct, but I wanted to add some extra information as most people using EB and RDS together should have the same requirement too - even if they don't know it yet.

First question: Why would you want the RDS instance to exist outside the EB environment? Answer: So that the lifetime of the RDS instance is not tied to the lifetime of the EB environment. i.e. when you remove an environment, you don't want to destroy the DB with it. There are very few reasons why you'd want to actually tie your RDS instance to your environment.

A problem with settings up RDS independently of EB is that you don't get the RDS_* variables automatically populated and therefore need to retrieve their values and populate them yourselves via web console or .ebextensions. It's not recommended that you add credentials to your code though, as that can be a security hole.

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 (e.g. password) every time. 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.

Related Topic