Part 8: WordPress on AWS ECS

It’s time to get to the core engine behind our WordPress tasks. The Elastic Container Service! (WordPress on AWS ECS)

ECS is Amazon’s container orchestration service, similar to Kubernetes. Kubernetes seems complicated to me, but if it is your thing, go for it…

AWS ECS Concepts

What is Amazon Elastic Container Service?

Here are the steps to follow to deploy WordPress on AWS ECS.

  1. Create a Task Definition
    1. Assign the task role and the task execution role
    2. Set a CPU and Memory Limit for each task (container)
    3. Add the EFS volume you created earlier, to store the files
    4. Configure the WordPress container settings
  2. Create and configure an ECS Cluster
  3. Create and configure an ECS Service
  4. (Optional) Service Auto Scaling

The Task role is used to give permissions to ECS Tasks and the containers running in it to access AWS resources.
The Task Execution role is used by the Fargate platform itself. You can create custom roles to access different features of AWS.

Create a Task Definition

ECS > Task Definitions > Create
Fargate > Name: wp-stack-fargate > Task role: ecs-task-full-access > Network: awsvpc > Task Execution role: ECSCustomTaskExecutionRole > Task Memory: 0.5GB > Task CPU: 0.25vCPU

Add volume > wp-files > Volume Type: EFS > File System: wp-stack-files > (Optional) Select Access Point > Enable transit encryption > Enable IAM authorization

(Scroll down to see this)

Add container >
Container name: wordpress
Image: wordpress:5.6
Port mappings: 80, tcp
Environment variables: Give the values for the container to connect to the RDS DB


Container definitions > wordpress > Storage and Logging > mount point: wp-files > container path: /var/www/html
Tick – Auto-configure CloudWatch Logs > Update

Create and configure an ECS cluster

Create cluster > Networking Only > Cluster Name: wp-cluster > Enable Container Insights

Create and configure an ECS service

Select wp-cluster > Services > Create
Launch Type: FARGATE > Task Def: wp-stack-fargate > Version: latest > Platform Version: 1.4.0 > Service Name: wp-service > Number of tasks: 1 > (Optional) Propagate tags from: Service > (Optional) Add Tags
Select VPC and subnets > Select existing Security Group > wp-stack-fargate
Health check grace period: 60
Load Balancing > Application LB > select ALB > wordpress:80:80 > Add to load balancer.
Select Target Group > wp-fargate
Production listener port: 443
Service Auto Scaling > Do not adjust
Review and Create Service.

Now, your WordPress task will start and connect to EFS and RDS. And your website will go live on port 80.

(Optional) Service Auto Scaling

Configure Service Auto Scaling to adjust your service’s desired count
Minimum number of tasks: 1
Desired number of tasks: 1
Maximum number of tasks: 2

Add scaling policy > Scaling policy type: Target > Policy Name: ScalingByClientRequests > ECS service metric: ALBRequestCount > Target value: 800 > Create

Conclusion: WordPress is running on AWS ECS

This concludes the series of posts on configuring Serverless WordPress on AWS. This method cost me around $50 to set up and run… Please use this only for very high traffic sites that require auto-scaling. This is not a cheap solution!

If you set this up as a trial, remember to delete all the resources you created to minimize your charges. Especially ECS and Aurora RDS!

If you tried this setup or if you have any suggestions, please leave them in the comments below… Thanks!



Leave a Reply