40

How do I change the configured RDS endpoint of an AWS Elastic Beanstalk environment? E.g. after the RDS database was deleted or should be replaced with a new RDS database.

tholu
  • 1,150
  • 2
  • 10
  • 24
  • How did you delete your RDS outside of beanstalk environment? I assume you created your RDS as part of beanstalk environment launch. – Rohit Banga May 15 '14 at 15:08
  • 1
    Using the RDS Interface. Yes, I did. But I found no way to change the defined RDS endpoint in Beanstalk. – tholu May 16 '14 at 16:42
  • 1
    If your goal is to just change the DB contents, you can dump the source DB and restore it to the destination DB. For that you will need to temporarily edit the security groups to allow the IP of the machine which is doing the DB dump. Concrete dump and restore syntax for PostgreSQL: https://coderwall.com/p/2e088w/rails-rake-tasks-to-dump-restore-postgresql-databases – Velizar Hristov Apr 07 '17 at 15:47
  • After much digging I stumbled across [this article](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.RDS.html) on the topic, which looks potentially helpful. – Jason Swett Dec 14 '18 at 16:28

4 Answers4

14

Update

The topic remains complex and the AWS Elastic Beanstalk (EB) documentation could still do a better job to clarify available options. The question has been about how to change an RDS endpoint, which seems to be read in two different ways:

  1. One could interpret it about how to attach an existing externally managed RDS endpoint to an existing (not new!) EB environment - this is indeed not possible, rather one would need to resort to handling this scenario from within the app itself as e.g. outlined in section Using an Existing Amazon RDS DB Instance with Python within Using Amazon RDS with Python.
  2. Rather, the OP asked about how to do that after the RDS database was deleted or should be replaced with a new RDS database, i.e. the RDS endpoint change is implied in the process of creating a new RDS database for an existing EB environment that already had one - this is indeed possible by means of the DBSnapshotIdentifier Option Value, which denotes The identifier for the DB snapshot to restore from. Once again the EB docs aren't exactly conclusive what this means, however, EB is using AWS CloudFormation under the hood, and the resp. entry for AWS::RDS::DBInstance - DBSnapshotIdentifier provides more details:

    By specifying this property, you can create a DB instance from the specified DB snapshot. If the DBSnapshotIdentifier property is an empty string or the AWS::RDS::DBInstance declaration has no DBSnapshotIdentifier property, the database is created as a new database. If the property contains a value (other than empty string), AWS CloudFormation creates a database from the specified snapshot. If a snapshot with the specified name does not exist, the database creation fails and the stack rolls back.

In other words, the typical result of updating any of the General Option Values from namespace aws:rds:dbinstance for an existing EB environment is the creation of a respectively adjusted RDS instance managed by EB, and thus a new RDS endpoint.
  • A specific sub scenario is the use of DBSnapshotIdentifier, which yields a new RDS instance managed by EB based on the referenced snapshot and can therefore be used to migrate (rather than attach) an existing externally managed RDS instance, albeit with considerable downtime based on the snapshot size.

Initial Answer

While unfortunately not specifically addressed within Configuring Databases with AWS Elastic Beanstalk, the AWS Elastic Beanstalk settings for an optional Amazon RDS database are handled via Option Values, see namespace aws:rds:dbinstance within General Options.

While the AWS Management Console hides many of those option values behind its UI, you can specify them explicitly when using the API via other means, both when creating an environment as well as when updating one (which is how you would change any settings of an RDS database instance) - see e.g. parameter --option-settings for update-environment from the the AWS Command Line Interface:

If specified, AWS Elastic Beanstalk updates the configuration set associated with the running environment and sets the specified configuration options to the requested value.

Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
  • 58
    I couldn't understand this answer. – João Paulo Motta Mar 16 '15 at 23:28
  • 5
    So basically you can update an environment's RDS settings using the EB command line interface, like this: *** eb update-environment --environment-name --option-settings aws:rds:dbinstance,, *** Sadly, there is no option to change the endpoint for an environment (only to change username, password, engine, instance class, etc - mainly those which you can change on the aws management console). I do not see how this answer is useful, or why it was accepted, it does not solve the problem at all. – akos Mar 28 '15 at 17:16
  • 1
    @korsosa, @JoãoPauloMotta - I have updated my answer with an attempt to clarify what is and what is not possible depending on different interpretations of the OP's question - specifically, it hopefully clarifies how to use the `DBSnapshotIdentifier` option value to provision a new EB managed RDS database for an existing EB environment from an existing RDS database's snapshot (still only possible via the EB or AWS CLI and not surfaced in the AWS Management Console). – Steffen Opel Mar 29 '15 at 16:05
  • 1
    @SteffenOpel Thanks, I thought you were talking about editing the DB endpoint of an existing EB environment (attaching an existing DB to an existing EB env) without creating a new DB instance, but now I see what I misunderstood. Thanks for the clarification! – akos Mar 30 '15 at 14:50
  • 4
    All that trouble to explain how to build the command, and which options to use, but not a single example implementation of the command itself? – Tony Chiboucas Sep 12 '16 at 19:00
  • @TonyChiboucas basically he used the the eb config command and set the DBSnapshotIdentifier field. I think that's it. – Gobi Dasu Jun 21 '17 at 06:22
  • 2
    @GobiDasu that's my point. We can't tell what he actually did, his explaination requires us to guess at the specifics, which are the very things people need when they come here. – Tony Chiboucas Aug 24 '17 at 20:51
  • 1
    Even after reading all the comments, the actual solution is still not clear. Can somebody please give a straight answer separately? (if you've figured it out) – Aditya Anand Jan 12 '20 at 06:34
3

I created a config file under .ebextensions folder that had the following content:

option_settings:
  - namespace: aws:rds:dbinstance
    option_name: DBSnapshotIdentifier
    value: <name-of-snapshot>

Upload and deploy and it will create a new RDS db using this snapshot.

bpn007
  • 31
  • 3
0

Hot-swapping out the data tier within an environment is discouraged because it breaks down the integrity of the environment. What you want to do is clone the environment, with a restored snapshot of the RDS instance. This means you'll have an identical environment with a different url 'host', and if everything went without a hitch, then you can swap environment urls in order to initiate a DNS swap.

After the swap happens and everything is good to go, you can proceed to deflate the old environment

ayc
  • 104
  • 3
  • 7
    When you say "clone the env with a restored snapshot of the RDS instnace" are you referring to Beanstalk's Clone Environment feature? As far as I can tell, it doesn't let you specify a snapshot to rebuild the env from. – Sitati Nov 14 '16 at 12:16
0

Follow the steps in the resolution to:

  • Use an Elastic Beanstalk blue (environment A)/green (environment B) deployment to decouple an RDS DB instance from environment A.
  • Create a new Elastic Beanstalk environment (environment B) with the necessary information to connect to the RDS DB instance.

check out the official answer below for more detailed solution

https://aws.amazon.com/premiumsupport/knowledge-center/decouple-rds-from-beanstalk/?nc1=h_ls