Using AWS Systems Manager to Upgrade WordPress

Share on:

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):

 1schemaVersion: "2.2"
 2description: "Download and install WordPress"
 3mainSteps:
 4- action: "aws:runShellScript"
 5  name: "example"
 6  inputs:
 7    runCommand:
 8    - "wget https://wordpress.org/latest.zip"
 9    - "mv latest.zip /var/www/html"
10    - "cd /var/www/html"
11    - "service httpd stop"
12    - "unzip -o latest.zip"
13    - "service httpd start"
14    - "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.