Modify Application

EC2

1.1 Click EC2 to navigate to the dashboard in the N. California (us-west-1) region.

1.2 Click the Instances (running) link.

1.3 Select the BackupAndRestoreSecondary instance, then click the Connect button.

1.4 Click the Session Manager link, then click the Connect button.

1.5 After a brief moment, a terminal prompt will display.

1.6 Let’s connect to the database in the secondary N. California (us-west-1) region.

sudo su ec2-user
cd /home/ec2-user

Replace the below backupandrestore-secondary-region.xxxx.us-west-1.rds.amazonaws.com with the endpoint you copied from RDS Section .

sudo mysql -u UniShopAppV1User -P 3306 -pUniShopAppV1Password -h backupandrestore-secondary-region.xxxx.us-west-1.rds.amazonaws.com

Type show databases.

MySQL [(none)]> show databases;

You should see the following:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| unishop            |
+--------------------+
5 rows in set (0.02 sec)

Type exit to return to the command prompt.

MySQL [(none)]> exit

1.7 Open the unishopcfg.sh file for editing with either nano or vi.

sudo nano unishopcfg.sh

Tip: You can use the vi (Debian ManPage ) or nano command (Debian ManPage ) to edit the document.

1.8 Replace the backupandrestore-secondary-region.xxxx.us-west-1.rds.amazonaws.com with the endpoint you copied from RDS Section . Change the *AWS_DEFAULT_REGION to us-west-1. Add the -dr to the end of the UI_RANDOM_NAME.

#!/bin/bash
export Database=backupandrestore-secondary-region.xxxx.us-west-1.rds.amazonaws.com
export DB_ENDPOINT=backupandrestore-secondary-region.xxxx.us-west-1.rds.amazonaws.com
export AWS_DEFAULT_REGION=us-west-1
export UI_RANDOM_NAME=backupandrestore-uibucket-xxxx-dr

Exit the editor, saving your changes.

1.9 Lets use the source command which reads and executes commands from the unishopcfg.sh file

source unishopcfg.sh

1.10 Let’s copy the application files to the S3 buckets.

If our S3 buckets contained application data then it would be necessary to schedule recurring backups to meet the target RPO. This could be done with Cross Region Replication. Since our buckets contains no data, only code, we will restore the contents from the EC2 instance.

sudo aws s3 cp /home/ec2-user/UniShopUI s3://$UI_RANDOM_NAME/ --recursive --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers

1.11 Reboot the EC2 instance so our changes take effect.

sudo reboot

Create application configuration file

2.1 Using your favorite editor, create a new file named config.json file. Set the host property equal to the EC2 public IPv4 DNS name copied from EC2 Section . Add (‘http://') and remove any trailing slash (/) if one is present. Finally, set the region property to us-west-1.

{
    "host": "http://{{Replace with your EC2 public IPv4 DNS name copied from EC2 section}}",
    "region": "us-west-1"
}

Your final config.json should look similar to this example.

{
    "host": "http://ec2-XXX-XXX-XXX-XXX.us-west-1.compute.amazonaws.com",
    "region": "us-west-1"
}

S3

3.1 Click S3 to navigate to the dashbarod.

3.2 Click the link for backupandrestore-uibucket-xxxx-dr.

3.3 Cick the Upload button.

3.4 Click the Add Files button and specify the config.json file..

3.5 In the Permissions Section section. Select the Specify Individual ACL permissions radio button. Enable the Read checkbox next to Everyone (public access) grantee.

3.6 Enable the I understand the effets of these changes on the specified objects. checkbox. Click the Upload button.

Click the Close button.

3.7 Click the Properties link. In the Static website hosting section, click the Edit button.

3.8 In the Static website hosting section select the Enable radio button. Enter index.html as the Index document and enter error.html as the Error document.

3.9 Click the Save changes button.

3.10 In the Static website hosting section. Click on the Bucket website endpoint link.

Congratulations ! You should see your application The Unicorn Shop in the us-west-1 region.