Elastic Architecture - AWS demo
Before

After

I completed a small project by Adrian Cantrill (https://github.com/acantril/learn-cantrill-io-labs/tree/master/aws-elastic-wordpress-evolution), which offered valuable insights on transforming a monolithic architecture into something scalable and decoupled. The project consisted of multiple stages, starting with a WordPress application running on an EC2 instance with MariaDB and media content stored together. Progressing through the stages, I learned how to decouple resources for scalability. Ultimately, the project showcased the implementation of a load balancer and autoscaling to address the limitations of the initial architecture and enhance safety and scalability.
In Stage 1, I manually created an EC2 instance and set up WordPress along with other components of the application. Key points I learned include using Parameter Store to securely pass important values without hardcoding and understanding the purpose of instance profiles in defining "who it is" and roles in defining "what it can do."Instance profiles play a crucial role in providing secure, consistent, and manageable role-based access for EC2 instances, simplifying the process of associating roles with instances and ensuring appropriate access without directly embedding credentials or roles.
Moving on to Stage 2, I launched an instance using a launch template and bootstrapped it using userdata, which expedited the process but posed limitations in terms of scalability and security due to all components residing in a single instance.
In Stage 3, I created an RDS subnet group, instance, and attached security group to enable communication with the WordPress app in another subnet. I also backed up data using the mysqldump command and migrated it to the RDS instance.
mysqldump -u $DBUser -p$DBPassword $DBName > a4lWordPress.sql
mysql -h $DBEndpoint -u $DBUser -p$DBPassword $DBName < a4lWordPress.sql
Change the WordPress config file to use RDS
sudo sed -i "s/'localhost'/'$DBEndpoint'/g" /var/www/html/wp-config.phpStage 4 introduced the use of an EFS file system to store media data uploaded to the WordPress website, addressing scalability concerns related to local storage. The process involved installing efs utils, migrating media content to EFS, and configuring the EFS file system to mount to the wp-content directory.
Install EFS utils,
sudo dnf -y install amazon-efs-utilsAfterward, you should transfer the current media files from wp-content to EFS, which involves multiple steps. Initially, duplicate the content to a temporary directory and create a new empty folder.
cd /var/www/html
sudo mv wp-content/ /tmp
sudo mkdir wp-content
then get the efs file system ID from parameter store
EFSFSID=$(aws ssm get-parameters --region us-east-1 --names /A4L/Wordpress/EFSFSID --query Parameters[0].Value)
EFSFSID=`echo $EFSFSID | sed -e 's/^"//' -e 's/"$//'`
Next .. add a line to /etc/fstab to configure the EFS file system to mount as /var/www/html/wp-content/
echo -e "$EFSFSID:/ /var/www/html/wp-content efs _netdev,tls,iam 0 0" >> /etc/fstab
mount -a -t efs defaults
copy the origin content data back in and add permissions
mv /tmp/wp-content/* /var/www/html/wp-content/
chown -R ec2-user:apache /var/www/
/etc/fstab is where you can see filesystems that are mounted to the instance
Stage 5 highlighted the need for further improvements in the architecture, such as implementing a load balancer to introduce health checks and self-healing capabilities. Additionally, I stress-tested the setup to confirm that the Auto Scaling Group provisioned instances as configured.
Target groups are the entities created by the auto scaling group, which are the destinations to which the load balancer directs the traffic.
The auto scaling group is set up with specifications such as the launch template, the security group to use, and the desired, minimum, and maximum capacities.
By integrating the auto scaling group with the load balancer, instances are provisioned by the ASG based on the configured conditions, and they are subsequently added to or removed from the target group.




Comments