Skip to main content

Using AWS Systems Manager to Upgrade WordPress

·220 words·2 mins
FTC Disclosure: As an Amazon Associate, I earn from qualifying purchases. Some links on this site are affiliate links.
Ben Piper
Author
Ben Piper
Wiley bestselling author — 100k+ copies, AWS Solutions Architect Associate (SAA) & Cloud Practitioner (CLF) bestsellers, 7+ books. 45 Pluralsight courses (4.7-star, 3,003 ratings). 10+ yrs 100% remote, solo CCNP ENCOR.

After years of manually upgrading my self-hosted WordPress installation, I decided it was finally time to apply some devops principles (namely automation) to this process.

I decided to use AWS Systems Manager (aka SSM). I started out by creating the following Command Document (which happens to be in YAML format because JSON is ugly):

schemaVersion: "2.2"
description: "Download and install WordPress"
mainSteps:
- action: "aws
:runShellScript"
  name: "example"
  inputs:
    runCommand:
    - "wget https://wordpress.org/latest.zip"
    - "mv latest.zip /var/www/html"
    - "cd /var/www/html"
    - "service httpd stop"
    - "unzip -o latest.zip"
    - "service httpd start"
    - "rm -f latest.zip"</code></pre>

The Command Document executes the bash commands in the runCommand section. It downloads the latest version of WordPress, stops Apache, unzips the files, restarts Apache, and then cleans up.

SSM uses an agent to carry out the bash commands. My instance runs Amazon Linux which comes with the agent preinstalled, so I didn’t need to install it.

Systems Manager can execute the Command Document at regular intervals to keep up with the typical WordPress release schedule of every 1-2 months. I can also trigger it manually if there’s a security or bugfix release I need.

To avoid catastrophe, I have the Amazon Data Lifecycle Manager for EBS Snapshots take daily snapshots of the instance, just in case something goes terribly wrong with an upgrade.