- Purpose: This CDK project will setup the AWS infrastructure for hosting a WordPress website using ECS Containers, RDS, and EFS.
- AWS Services Used:
- Route53
- EC2 NAT Instances
- VPC with 2 AZs
- Secrets Manager
- RDS MySQL
- Elastic File System
- Application Load Balancer
- ECS Cluster with Fargate Spot
- Bitnami WordPress image
- An AWS account
- Node.js and npm (or another supported CDK language/package manager)
- AWS CLI, SSO Profile, or Access Keys
- AWS CDK Toolkit installed globally (
npm install -g aws-cdk
)
-
Clone the repository:
git clone [https://github.com/mkober/wordpress-fargate-cdk.git
-
Install dependencies for the stacks
cd stacks npm install
-
Create .env file with the following:
REGION: string, ACCOUNT: string, VPC: string, DOMAIN: string, DOMAIN_WILDCARD: string, DATABASE_INSTANCE: string, DATABASE_NAME: string, DATABASE_USER: string,
-
Bootstrap the CDK
cdk bootstrap
-
Sythesize the CloudFormation Template
cdk synth
-
Deployment
cdk deploy
The cdk.context.json is being ignored. This file is generated and referenced when you sythesize with the cdk. In this file your AWS Account ID, Hosted Zone, and Domain Name are stored. You should commit cdk.context.json to your personal repo to avoid non-deterministic behavior. If you don't the deploy will create a new stack each time.
In order to complete the WordPress setup you will need to edit the wp-config.php file to define the FORCE_SSL_ADMIN, WP_HOME, and WP_SITEURL. Without this you see an authentication loop issue when trying to login to the admin. This will be accessible in the EFS mounted volume under /bitnami. In order to make this modification you will need to remote into one of the Fargate tasks using the AWS CLI.
aws ecs execute-command \
--region us-east-1 \
--cluster [cluster-name] \
--task [task id, for example 0f9de17a6465404e8b1b2356dc13c2f8] \
--container WordpressContainer \
--command "/bin/bash" \
--interactive
define( 'FORCE_SSL_ADMIN', true); \
define( 'WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/' ); \
define( 'WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/' );
This project is licensed under the MIT License - see the license.txt file for details.