At this stage, you’ve successfully created a new PostGreSQL Database on Amazon RDS and migrated your existing Database and set your ongoing replication settings.
Now, you will change the Database endpoint configuration settings on your Source Java Application server so that your application starts using the new migrated database.
Go to RDS Service, and click “Databases” from the right pane.
Connect to the Source-Java-Webserver where your Java application runs.
You have multiple options to connect your Web Server. Check this article for more detail on how to connect to your Linux instance.
You can connect to your Web server via using AWS Systems Manager - Session Manager. Session Manager provides secure and auditable instance management without the need to open inbound ports, maintain bastion hosts, or manage SSH keys.
Go to your Amazon EC2 instances, select your Java Web Server and Click “Connect”.
Choose “Session Manager” and click “Connect”
If you prefer to SSH into the webserver, you would need the following details.
a. Public DNS Name of the webserver
b. Username configured in the webserver
You can find this information in the output section of the cloudformation stack. The stack can be accessed by navigating to the CloudFormation console.
|SSHKey||SSHKeyURL (You need to create .pem file from this key)|
|Public DNS Name||JavaWebServerDNSName|
For SSH key, you need to create a .pem file via copying the key from the URL to your text editor and save it as .pem file.
Your application gets the Database connection configurations from your server environment variables. Open the environment file under /etc folder and update the “RDS_HOSTNAME” with the RDS endpoint you’ve copied earlier.
sudo su nano /etc/environment
Once you open the file, you will see that RDS_HOSTNAME is already set to “10.0.0.140” which is source DB private IP address. Change the parameter with RDS endpoint and save and exit from the file.
After the changes, exit from the file with “ctrl+x” and type “y” and hit enter to save the file with the same name.
In order to make environment variable changes active, run the below command.
Now, restart your Tomcat Webserver to trigger the changes on your web application with below commands.
cd /usr/local/tomcat8/bin/ ./shutdown.sh ./startup.sh
Go to App2Container Cloudformation Stack, and copy “JavaWebApplicationURL” parameter from the Output section of the App2ContainerWorkshop
Open the browser and paste your “JavaWebApplicationURL”.
You should see your Web application running successfully as below.
Navigate to “BROWSE MOVIES” tab, you should see the list of unicorn movies.
You have successfully migrated your Database and your Web Application is now using the migrated RDS Database.