Build Solutions across VPCs with Peering

1 hour
  • 5 Learning Objectives

About this Hands-on Lab

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, we create a new VPC for our WordPress blog to run from. We then create a VPC peering connection between the new VPC and an existing database VPC. By the end of this lab, the user will understand how to create a new VPC from scratch, attach internet gateways, edit routing tables, and peer multiple VPCs together.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create Web_VPC Subnets and Attach a New Internet Gateway

Using the AWS console, create the Web_VPC VPC with the 192.168.0.0/16 IPv4 CIDR block.

Create the WebIG internet gateway.

Modify the route table to attach the internet gateway to the Web_VPC

Create a Peering Connection

Peer the newly created Web_VPC with the DB_VPC. Ensure Web_VPC is the requester and that the request has been accepted.

Create an EC2 Instance and configure WordPress

Launch a new public facing Ubuntu Server 20.04 LTS EC2 instance in the Web_VPC VPC using the provided bootstrap user data script.

#!/bin/bash
sudo apt update -y
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip perl mysql-server apache2 libapache2-mod-php php-mysql -y
wget https://github.com/ACloudGuru-Resources/course-aws-certified-solutions-architect-associate/raw/main/lab/5/wordpress.tar.gz
tar zxvf wordpress.tar.gz
cd wordpress
wget https://raw.githubusercontent.com/ACloudGuru-Resources/course-aws-certified-solutions-architect-associate/main/lab/5/000-default.conf
cp wp-config-sample.php wp-config.php
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
mkdir wp-content/uploads
chmod 775 wp-content/uploads
mv 000-default.conf /etc/apache2/sites-enabled/
mv /wordpress /var/www/
apache2ctl restart

Configure wordpress by editing /var/www/wordpress/wp-config.php to point DB_HOST to the RDS database endpoint.

Modify the RDS Security Groups to Allow Connections from the Web_VPC VPC

The RDS instance requires a security group modification to allow access from 192.168.0.0/16.

Test WordPress

Visit the IP address of your EC2 instance in a web browser and confirm WordPress is working correctly and communicating with the RDS instance via VPC peering.

Additional Resources

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?