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

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 descriptionFollow these steps to decouple your database from an Elastic Beanstalk environment without affecting the health of the environment:Create an Amazon RDS DB snapshot.Protect your RDS DB instance from deletion.Create a new Elastic Beanstalk environment.Perform a blue/green deployment.Update the database deletion policy for beanstalk environment A.Decouple the RDS instance from beanstalk environment A.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.

ResolutionCreate an RDS DB snapshotOpen the Elastic Beanstalk console.Choose the Elastic Beanstalk environment that you want to decouple from your RDS DB instance (environment A).In the navigation pane, choose Configuration.For Database, choose Modify.Select Endpoint.Create an RDS DB snapshot of your RDS DB instance.Protect your RDS DB instance from deletionOpen the Amazon RDS console.Choose your database, and then choose Modify.In Deletion protection, select the Enable deletion protection option.Choose Continue.In Scheduling Modifications, choose Apply immediately.Choose Modify DB Instance.Refresh the Amazon RDS console, and then verify that deletion protection is turned on.Create a new Elastic Beanstalk environmentYour 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.Create environment B.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.Verify that environment B connects to the existing RDS DB instance, and that your application works correctly.Perform a blue/green deployment to avoid downtimeOpen the Elastic Beanstalk console for environment B.Swap the environment URLs of the old and new Elastic Beanstalk environments.Note: For more information, see Blue/green deployments with Elastic Beanstalk.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 AOpen the Elastic Beanstalk console for environment A.In the navigation pane, choose Configuration.In Database configuration, choose Edit.In Database settings, set the Database deletion policytoRetain.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 AOpen the Elastic Beanstalk console for environment A.In the navigation pane, choose Configuration.In Database configuration, choose Edit.In Database settings, verify that the Database deletion policyis set toRetain.Go to the Database connection section, and choose Decouple database.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 environmentAfter 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.