Build Solutions Across VPCs with Peering
Build Solutions Across VPCs with Peering
Build Solutions Across VPCs with Peering
-
learn.acloud.guru/handson/b9756e9f-5140-4ec7-b9b7-0ffaed561910/course/certified-solutions-architect-associate
#
Introduction
A VPC peering connection is a networking connection between two VPCs that enables you
to route traffic between them using private IPv4 addresses or IPv6 addresses. In this lab, you
will create a new VPC for your WordPress blog to run from. You will then create a VPC
peering connection between the new VPC and an existing database VPC. By the end of this
lab, you will understand how to create a new VPC from scratch, attach internet gateways,
edit routing tables, and peer multiple VPCs together.
Solution
Log in to the AWS Management Console using the credentials provided on the lab
instructions page. Make sure you're in the N. Virginia (us-east-1) Region throughout the lab.
Create a VPC
1. Use the top search bar to look for and navigate to VPC.
2. Under Resources by Region, click VPCs.
3. Use the top search bar to look for and navigate to RDS in a new tab.
4. Click DB Instances, and observe the instance created for this lab.
Note: Keep this tab open for use later on in the lab.
Create a Subnet
1/6
4. Under Subnet settings, set the following values:
Subnet name: Enter WebPublic.
Availability Zone: Select us-east-1a.
IPv4 CIDR block: Enter 192.168.0.0/24.
5. Click Create subnet.
2/6
12. Click Save changes.
13. Go back to Route Tables, and select the checkbox for the DB_VPC instance with a Main
column value of Yes.
14. Underneath, select the Routes tab, and click Edit routes.
15. Click Add route.
16. Set the following values:
Destination: Enter 192.168.0.0/16.
Target: Select Peering Connection, and select the peering connection that
appears in the list.
17. Click Save changes.
3. Scroll down and under Quick Start, select the Ubuntu image box. (You can skip the
Name field before this.)
4. Under Amazon Machine Image (AMI), click the dropdown and select Ubuntu Server
24.04 LTS.
6. For Key pair, click the dropdown and select Proceed without a key pair.
11. Set the following values for the new rule (i.e., Security group rule 2):
3/6
13. At the bottom, under User data, copy and paste the following bootstrap script:
#!/bin/bash
sudo apt update
sudo apt install apache2 php libapache2-mod-php php-mysql php-curl php-gd php-
mbstring php-xml php-xmlrpc php-soap php-intl php-zip unzip -y
sudo ufw allow in "Apache"
sudo a2enmod rewrite
systemctl restart apache2
cd /tmp/ && wget https://wordpress.org/latest.zip
unzip latest.zip -d /var/www
chown -R www-data:www-data /var/www/wordpress/
mv /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
cd /var/www/wordpress/
perl -pi -e "s/database_name_here/wordpress/g" wp-config.php
perl -pi -e "s/username_here/wordpress/g" wp-config.php
perl -pi -e "s/password_here/wordpress/g" wp-config.php
perl -i -pe'
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/put your unique phrase here/salt()/ge
' wp-config.php
wget https://raw.githubusercontent.com/ACloudGuru-Resources/course-aws-
certified-solutions-architect-associate/main/lab/5/000-default.conf
mkdir wp-content/uploads
chmod 775 wp-content/uploads
mv 000-default.conf /etc/apache2/sites-enabled/
systemctl restart apache2
Note: It may take a few minutes for the new instance to launch.
15. From the green box that appears after the instance launches, open the link for the
instance in a new browser tab.
16. Observe the Instance state column, and check to ensure it is Running before you
proceed.
17. Select the checkbox for the new instance and click Connect.
Note: The startup script for the instance may take a few minutes to complete and
you may need to wait for it to complete before proceeding with the next step.
4/6
19. To confirm WordPress installed correctly, view the configuration files:
cd /var/www/wordpress
ls
24. Go back to the tab with the terminal, and scroll down to /** MySQL hostname */.
26. Replace localhost with the RDS endpoint you just copied. Ensure it remains wrapped
in single quotes.
27. Press ESC followed by :wq, and press Enter. Leave this tab open.
Modify the RDS Security Groups to Allow Connections from the Web_VPC VPC
1. Go back to your RDS browser tab.
2. In Connectivity & security, click the active link under VPC security groups.
3. Checkmark the DatabaseSG Security Group.
4. At the bottom, select the Inbound rules tab.
5. Click Edit inbound rules.
6. Click Add rule.
7. Under Type, search for and select MYSQL/Aurora.
8. Under Source, search for and select 192.168.0.0/16.
9. Click Save rules.
10. Return to the terminal page.
11. Below the terminal window, copy the public IP address of your server.
12. Open a new browser tab and paste the public IP address in the address bar. You
should now see the WordPress installation page.
13. Set the the following values:
Site Title:.
Username:.
Your Email:test@test.com.
14. Click Install WordPress.
Abdur Razzaq
AWS DevOps Engineer
5/6
15. Reload the public IP address in the address bar to view your newly created WordPress
blog.
Conclusion
Congratulations — you've completed this hands-on lab!
Troubleshooting
If the website isn't loading the way you expected at the end of this lab, here are some tips to
help troubleshoot:
Check the status of the lab objectives - are any not yet completed?
Is everything you set up ready to use? Check things like the VPC peering connection,
which requires you to specifically accept the connection request.
Does the database error page load after a minute or so of waiting, or does no page
load at all? This gives a hint on whether the issue may be with the peering or the
security groups.
Abdur Razzaq
AWS DevOps Engineer
6/6