Change DB Endpoint at Application

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.

  1. Go to RDS Service, and click “Databases” from the right pane.

    • Select your RDS database “unicorn” which you’ve created earlier.
    • From the “Connectivity & Security” tab, copy Endpoint URL to your notepad. You will use this endpoint in the next steps.

    source-endpoint

  2. 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”

        create-s3-bucket

    OR

    • 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
      c. SSHKey

      You can find this information in the output section of the cloudformation stack. The stack can be accessed by navigating to the CloudFormation console.

      Parameter Value
      Username ubuntu
      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.

  1. 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. source-endpoint

    • After the changes, exit from the file with “ctrl+x” and type “y” and hit enter to save the file with the same name.

  2. In order to make environment variable changes active, run the below command.

    source /etc/environment
    
  3. 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
    
    • you should see the below output on your terminal.

    source-endpoint

  4. Go to App2Container Cloudformation Stack, and copy “JavaWebApplicationURL” parameter from the Output section of the App2ContainerWorkshop

  5. Open the browser and paste your “JavaWebApplicationURL”.

    • You should see your Web application running successfully as below.

      source-endpoint

    • Navigate to “BROWSE MOVIES” tab, you should see the list of unicorn movies.

      source-endpoint

Congratulations

You have successfully migrated your Database and your Web Application is now using the migrated RDS Database.