Skip to content

Repository to create a scalable and fault tolerant wordpress environment on AWS through automation scripts

Notifications You must be signed in to change notification settings

maikelpenz/wordpress-aws-automation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wordpress aws automation

This project is designed to automate the creation of a Wordpress environment on AWS.

The architecture is similar to the wordpress setup found as part of the AWS Certified Solutions Architecht-Associate course provided by the acloudguru platform, however besides automating it, this project goes beyond by setting up VPCs for better security.

Table of Contents

Architecture
Requirements
Usage
Thoughts

Architecture

The architecture is highly customizable and can be set by updating the file generate_wordpress_stacks.py inside the modules folder  

Requirements

The AWS CLI is an open source tool that enables you to interact with AWS services using commands in your command-line shell. Without going much into detail it is needed to store a valid aws profile on your computer that will be used for the wordpress deployment.

Library used to generate CloudFormation templates

$ pip install troposphere

Tool and Library that orchestrate the creation and updates of CloudFormation stacks

$ pip install --upgrade pip setuptools
$ pip install stacker

 

Usage

The following steps show how to deploy the wordpress environment:

1. Environment configuration

The file modules/generate_wordpress_stacks.py contains variables that define what your environment will look like. The following image shows an example of architecture that can be generated by this file

ArchitectureImage

Things to note:

  • A bastion VPC is created and peered with the private VPC to only enable SSH access to wordpress instances through the bastion host.
  • Write Node = where you make changes to the website. e.g: add new posts.
  • Read Nodes = the wordpress website. Read Nodes are part of an auto scaling group and behind a load balancer for high availability and traffic distribution.
  • Once a minute, changes made to the website through the write node get uploaded to a S3 Bucket and read nodes download these changes to update the website.
  • The database lives in a private VPC (without internet access) and can be configured for Multi-AZ.
  • Cloudfront is used to deliver blog post images to users.

Most variables are self explanatory but I will highlight a few:

stage = defines the target environment. You can deploy multiple wordpress environments in the same account. e.g: prod, dev, test
key_name = Key Pair that will be used. If you don't have a key yet go to the AWS console > EC2 > Key Pairs and generate your pair.
instance_ami = Linux AMI for your instances. e.g: ami-009d6802948d06e52

If you want to use the architecture shown in the image above you only need to change variables between < >

2. Generate cloudformation stacks

Run the file modules/generate_wordpress_stacks.py to generate the cloudformation stacks.

$ python .\modules\generate_wordpress_stacks.py

The cloudformation templates in yaml format can be found inside the modules folder

3. Using Stacker to deploy the stacks

First, make sure you have an aws profile set on ~.aws\credentials that matches the profile name found inside the file stacker/config/environments/prod.env. e.g: default

Run stacker to deploy the stacks:

$ stacker build .\stacker\config\environments\prod.env .\stacker\config\config.yaml

To destroy the environment:

$ stacker destroy .\stacker\config\environments\prod.env .\stacker\config\config.yaml --force

4. Acessing Wordpress

Once stacker has finished deployed the stacks:

  • Go to the AWS Console > EC2 > Instances and copy the public DNS of the Read Node and open on your browser.
  • Follow the wordpress installation process and fill up the form according to the variables set on the file modules/generate_wordpress_stacks.py (e.g: username, password, Database Name). For the Database host, on the AWS Console go to RDS and copy the public endpoint generated for your database.

After you finished the installation, wait about 1 minute so the read nodes download the latest changes and you can access your wordpress blog.

5. Important: Cloudfront manual set up after installation

Unfortunatelly after you configure your wordpress environment through the webpage a wordpress configuration file gets overwritten and you need to manually update the file to connect cloudfront properly. Follow these steps:

  • SSH into the Bastion Host and from the bastion host SSH to your write node
  • Update the .htaccess file to allow url rewrite and point your images to Cloudfront
nano /var/www/html/.htaccess

Remove what is in the file and paste the following (remember to replace in the code below the section asking for your cloudfront domain name):

Options +FollowSymlinks 
RewriteEngine on 
rewriterule ^wp-content/uploads/(.*)$ http://<YOUR CLOUDFRONT DOMAIN NAME>/$1 [r=301,nc]

Restart apache httpd, just in case:

sudo service httpd restart

 

Thoughts

This project was developed to practice cloud automation, so there are definetly better ways to achieve the same result.

Stacker for example provide blueprints so you don't need to generate the cloudformation yaml file and use their templates instead.

Also, if you want to use this solution for your "production" blog you may want to add a public domain to your website. Use the AWS service called Route 53 to point a record to your load balancer.

About

Repository to create a scalable and fault tolerant wordpress environment on AWS through automation scripts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages