How to setup wordpress with auto-scaling enabled using AWS infrastructure

I came across the following idea recently.
How to setup and host wordpress website using one of auto-scaling infrastructure provided in Amazon Web Services. Which can be described as below:

It called Elastic Cluster Services (ECS) which come with the Task Definition and Services setting then can be setup to has some part exposed to outside world via Application Load Balancer (ALB).
The database is running on Amazon Relational Database Service (RDS).
The user uploaded images is hosted on Amazon Simple Storage Service (Amazon S3) combined with a wordpress plugin called WP Offload Media Lite. While the whole wordpress codebases is stored on Elastic Filesystem (EFS) then mounted via Network File System (NFS) on each instance.
And all these are available for FREE because it is part of AWS Free Tier.
(first one year).
Except if you somehow scaled the Amazon Elastic Compute Cloud (Amazon EC2) in “ECS

Roughly, here is the receipt on how to setup ECS with RDS, EFS and S3 that would work with vanilla wordpress.

1. Setup a new AWS account (so that you will be eligible for the Free Tier)
– this will need a new credit card that can be charged on overseas.
– I opted to a call from AWS to verify the contact number instead of the SMS.

2. Setup the VPC that split between “Public Subnet” and “Private Subnet”
– Because you will not wanting any of your ECS task being assigned a Public IPv4 address upon spinning up.

3. Setup Subnets and its NAT Gateway for the privates ones.
– you will need at least two of them each, to support the High Availability Zone.

4. Setup RDS with the internal access only allowed.
– set with security group that allow connection to 3306 port
– from your defined subnets.
– I just select MySQL 8.0.21 for the version running on t2.micro/10Gb (Free Tier)

5. Setup S3 bucket
– that will sit in the public subnet and allowed public access to its.

6. Setup EFS
– I just set the minimal size for this as per Free Tier.
– this should sit in the private subnet and allowed only your private subnets IPs to access it.

7. Create an IAM policy roles
– that will be able to use S3 and EFS infrastructure.
– should be able to read/write the S3 bucket
– should be able to mount/read/write the EFS

8. Setup Application Load Balancer for port HTTP and HTTPS (port 80/443)
– the target should be IPs on the ECS instances -> Task.

9. Setup the ECS Cluster infra
– Set it to be tied to your VPC and Subnet (public)
– For this one I just select t2.micro
– for the setup, you want to tied this your public subnet first instance to ensure everything can
be connected.
– set to run with key/pair for SSH access in cases need to debug it.

10. Setup the ECS’s Task definitions.
– here you should be able to add the EFS endpoint and mount it to “/var/www/html”
– Set the image source to point to wordpress:latest
– Define the working directory to “/var/www/html”
– Define the Docker variable of WORDPRESS_DB, WORPRESS_HOST, etc

11. Setup the Service from the Task.
– Here will be set the option to point to Application Load Balancer.
– that will be updated with latest target whenever new task is running.

12. Setup the security group for the ALB
– Set the certificates for the HTTPS
– and allow public access to it. port 80 and port 443.

Now let’s go into detail for each step.

1. Setup AWS account and activate it.
Once you have created a new AWS account.
-Activate it and add the default payment method.

You may want to check the Free Tier.

2. Setup the VPC.
Once successfully activated new AWS account.

Firstly, we need to setup the VPC for the AWS.
Then create subnet for the VPC. I would split them to at least two.
Private subnet and Private Subnet.

The only different between these two is one didn’t have direct access to Internet via Internet Gateway.
And it would be assigned with a IPv4 Public IP Address.

Subnet Settings

Route Settings – public subnet

Route Settings – private subnet

You may want to disable the NAT gateway in the private subnet if it does not require internet access.
Please also enable DNS hostname and DNS resolutions because it is needed for the EFS to work later.

Once the VPC is ready. You may start to create all the components needed for the ECS to work.

3. setup the Database into RDS

Firstly set the RDS into private subnet.

and assign necessary security group with proper access to the database port 3306.

4. Setup the S3 bucket.

Next, set the S3 bucket with the public permission to read.

5. Setup the EFS.
Then setup the EFS into the private subnet as well.

allow the proper access to it as well.

6. Setting the IAM roles to be used in ECS.
Create a new IAM roles with following attached policies.

7. Setup ALB with target IP.
Setup the Application Load Balancer for HTTP and HTTPS

8. Setup ECS infrastructure.

9. Setup the Task definition
Set it to load from the remote docker images.

At the task definition, please add the volume to the EFS.

expected result.

Then add it into the container setting.

set the proper ENV setting for it to work and point to the RDS database.

Check the final result for the container in task should be something like:

Ensure it can be successfully manually started and status is changed to “RUNNING” before proceed with the next step.

Then stop the task and setup the services so that it can be started automatically.

10. Setup the Services and map it to use ALB.

11. Set the Security Group to allow public access.

12. Setup CNAME into DNS and point it wordpress and Install WP plugins.

Once you uploaded an images, it will end up into bucket as below.

And that’s it.

You can set the auto scale setting the EC2 – auto scaling group.

Just need to be careful as it may cost extra buck with additional instance running.
You can always check the Billing tabs for the expected charged.

Ensure that you also cleaned up unused resources as it may also cost you extra.. like the unused IP allocation address. :)

Anything else you would like to add, feel free to put into the comment box below.

Namran Hussin: a soft spoken guy... with exceptional interest in computers and technology. I love to learn new thing and also love to break thing for the sake of learning.. but I do abide to the self-imposed limitation or certain thing such as social thing in life, thing can be done and thing that must be avoided at whatever cost such as drug,illegal tracking, smoke,illicit activity..etc.muahahaha let's share what we had in this short term of the life.! make it worth of the living.~
Related Post
Leave a Comment