Previous: Enable Virtual Private Cloud (VPC) Peering, Up: Task 5---Migrating to Amazon Relational Database Service [Contents][Index]
In this task, you will again update your application configuration file
(config.php
) to point to the Amazon RDS database.
Because your current Lightsail instances all run under a load balancer, it would be unwise to reconfigure only some of them to point to the Amazon RDS database. Doing so could result in a situation where the load balancer would present some front ends that connect to the Lightsail database, and other front ends that connect to the Amazon RDS database.
To avoid this situation, you will deploy a new PHP front end instance based on your existing snapshot, and then modify that instance.
PHP-fe-1
:
php-fe-rds
.
Now that you have a new instance to work from, you can reconfigure the configuration file to point to the Amazon RDS database.
php-fe-rds
instance through SSH.
tasks-db
to
access the database details screen.
php-fe-rds
instance.
RDS_ENDPOINT
) to hold the value
of your RDS database endpoint by:
RDS_ENDPOINT=<rds-endpoint>
dbmasteruser
) and
the password (taskstasks
):
RDS_USERNAME=dbmasteruser RDS_PASSWORD=taskstasks
echo "Endpoint = "$RDS_ENDPOINT echo "Username = "$RDS_USERNAME echo "Password = "$RDS_PASSWORD
cat /opt/bitnami/apache2/configs/config.php.bak | \ sed "s/<endpoint>/$RDS_ENDPOINT/; \ s/<username>/$RDS_USERNAME/; \ s/<password>/$RDS_PASSWORD/;" \ > /opt/bitnami/apache2/configs/config.php.rds_db
config.php
with
the new version:
cp /opt/bitnami/apache2/configs/config.php.rds_db /opt/bitnami/apache2/configs/config.php
config.php
file:
cat /opt/bitnami/apache2/configs/config.php
http://PHP-FE-RDS/install.php
You should get the following error:
SQLSTATE[HY000] [1049] Unknown database 'tasks'
This is because while you can reach the Amazon RDS server, the ’tasks’ database has not yet been created.
In the SSH window create an environment variable name
LS_ENDPOINT
to hold the value of the endpoint of your database.
LS_ENDPOINT=<IP-address>
Your variable should look similar to:
LS_ENDPOINT='ls-966d5bf6be8ee5178432a633398bf4256bfcab69.cucxkvhp11zu.us-west-2.rds.amazonaws.com'
dbmasteruser
) and
the password (taskstasks
):
LS_USERNAME=dbmasteruser LS_PASSWORD=taskstasks
echo "Endpoint = "$LS_ENDPOINT echo "username = "$LS_USERNAME echo "Password = "$RDS_PASSWORD
tasks.sql
:
mysqldump -u $LS_USERNAME \ --host $LS_ENDPOINT \ --databases tasks \ --single-transaction \ --compress \ --order-by-primary \ --set-gtid-purged=OFF \ -p$LS_PASSWORD > tasks.sql
mysql
command line tool:
mysql -u $RDS_username \ --port=3306 \ --host=$RDS_ENDPOINT \ -p$RDS_PASSWORD
source tasks.sql
http://<IP-address>
You should see that the tasks you created originally are now present in the database that is managed by Amazon RDS.
From this point, you could repeat the steps from Task 4 and create a new
snapshot from your php-fe-rds
instance, deploy two new instances from
that new snapshot, and replace the existing instances in your load
balancer with your three new instances that use Amazon RDS.
This process would give you a redundant web front end that runs in Amazon Lightsail, with the database running in Amazon RDS. However, for this lab you will not do that.