How do I decouple an Amazon RDS instance from an Elastic Beanstalk environment without downtime, database sync issues, or data loss?

4 分的閱讀內容
1

I have an Amazon Relational Database Service (Amazon RDS) DB instance attached to my AWS Elastic Beanstalk environment. I want to remove the dependencies between the instance and the environment while avoiding downtime, database sync issues, and data loss.

Short description

Follow these steps to decouple your database from an Elastic Beanstalk environment without affecting the health of the environment:

  1. Create an Amazon RDS DB snapshot.
  2. Protect your RDS DB instance from deletion.
  3. Create a new Elastic Beanstalk environment.
  4. Perform a blue/green deployment.
  5. Update the database deletion policy for beanstalk environment A.
  6. Decouple the RDS instance from beanstalk environment A.
  7. Terminate the old Elastic Beanstalk environment.

Important: Attaching an RDS DB instance to an Elastic Beanstalk environment is ideal for development and testing environments. However, it's not recommended for production environments because the lifecycle of the database instance is tied to the lifecycle of your application environment. If you terminate the environment, then you lose your data because the RDS DB instance is deleted by the environment. For more information, see Using Elastic Beanstalk with Amazon RDS.

Resolution

Create an RDS DB snapshot

  1. Open the Elastic Beanstalk console.
  2. Choose the Elastic Beanstalk environment that you want to decouple from your RDS DB instance (environment A).
  3. In the navigation pane, choose Configuration.
  4. For Database, choose Modify.
  5. Select Endpoint.
  6. Create an RDS DB snapshot of your RDS DB instance.

Protect your RDS DB instance from deletion

  1. Open the Amazon RDS console.
  2. Choose your database, and then choose Modify.
  3. In Deletion protection, select the Enable deletion protection option.
  4. Choose Continue.
  5. In Scheduling Modifications, choose Apply immediately.
  6. Choose Modify DB Instance.
  7. Refresh the Amazon RDS console, and then verify that deletion protection is turned on.

Create a new Elastic Beanstalk environment

Your new Elastic Beanstalk environment (environment B) must not include an RDS DB instance in the same Elastic Beanstalk application.

Note:  To perform a blue/green deployment (or CNAME swap) later, make sure that environment A and environment B are part of the same application.

  1. Create environment B.
  2. Connect environment B to the existing RDS DB instance of environment A.
    Note: For more information, see Launching and connecting to an external Amazon RDS instance in a default VPC.
  3. Verify that environment B connects to the existing RDS DB instance, and that your application works correctly.

Perform a blue/green deployment to avoid downtime

  1. Open the Elastic Beanstalk console for environment B.
  2. Swap the environment URLs of the old and new Elastic Beanstalk environments.
    Note: For more information, see Blue/green deployments with Elastic Beanstalk.
  3. Verify that the URL of environment B responds, and that your application works correctly.

Important: Don't terminate environment A until the DNS changes are propagated, and your old DNS records expire. DNS records can take up to 48 hours to expire. DNS servers don't clear old records from their cache based on the time to live (TTL) that you set on your DNS records.

Update the Database deletion policy for beanstalk environment A

  1. Open the Elastic Beanstalk console for environment A.
  2. In the navigation pane, choose Configuration.
  3. In Database configuration, choose Edit.
  4. In Database settings, set the Database deletion policytoRetain.
  5. Choose Apply. It will take a few minutes to save the configuration change.

Important: Do not proceed to the next step until the Database deletion policy change is applied to beanstalk environment A.

Decouple the RDS instance from beanstalk environment A

  1. Open the Elastic Beanstalk console for environment A.
  2. In the navigation pane, choose Configuration.
  3. In Database configuration, choose Edit.
  4. In Database settings, verify that the Database deletion policyis set toRetain.
  5. Go to the Database connection section, and choose Decouple database.
  6. Choose Apply to initiate the database decoupling operation.

Note: The database remains operational during this period, and it usually takes less than five minutes to decouple a database.

Terminate the old Elastic Beanstalk environment

After the new environment’s functionality is validated, terminate the old Elastic Beanstalk environment (environment A).

When you terminate the environment, all Elastic Beanstalk resources are deleted, except for the RDS DB instance and the RDS security group that were created by Elastic Beanstalk.


AWS 官方
AWS 官方已更新 1 年前
6 評論

It would be great if the error messages and the underlying decouple issues were published and explained in plain English as to the cause and what to do next. For example, what do these error messages mean in the above context? "DB Allocated storage should be more than the previous value." "RDS DB Engine option setting is not allowed to changed"

回答 6 個月前

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
管理員
回答 6 個月前

I am getting the same errors when trying to decouple a database from Elastic Beanstalk:

"DB Allocated storage should be more than the previous value." "RDS DB Engine option setting is not allowed to changed"

回答 6 個月前

I am also getting an error when i try to decouple my database. I however just get the "DB Allocated storage should be more than the previous value." error message even though the only change i made was selecting decouple database. Is this a bug in AWS or am I missing something?

Lukas
回答 5 個月前

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
管理員
回答 5 個月前

I was able to do this from the CLI but not from the web console. In the web console, I received the same errors that the other people mentioned.

  1. Enable termination protection on my RDS instance
  2. Update ENV VARS for the EB environment to pass the hostname and port (once decoupled, ElasticBeanstalk will no longer provide these automatically in the preconfigured RDS_HOSTNAME and RDS_PORT env vars).
  3. Run eb config to open an editor. In the aws:rds:dbinstance section (for me, it was at the bottom), change DBDeletionPolicy to Retain
  4. Save and exit
  5. EB will automatically update your environment configuration
  6. Run eb config to open an editor. Now change HasCoupledDatabase to 'false'
  7. Save and exit
  8. EB will automatically update your environment configuration
回答 20 天前