AWS auto-scale shared Wordpress web server - AMI vs user scripts

I'm planning to use EFS to share all Wordpress files and likely Redis for shared session management, however this is not the topic of this question.

Hmm, that's a pity. I was just about to suggest that you should offload all the configuration and user data from the instances to a durable, shared storage and use the instances purely as stateless web servers - easy to scale, easy to replace. Conversion from local storage to EFS is easy (it's not really a re-architecting the system, only moving some directories to EFS) and can be done with very little downtime.

All the Apache / Nginx / PHP and Wordpress config files as well as the uploaded user media files will then be stored on the shared filesystem and the instances will self-configure from there.


Anyway, if you straight away dismiss the best and obvious solution we're left with suggesting some inferior options. I've got a CloudFormation template that does something close to what you want:

  • The EC2 instance is in AutoScaling group of min=1/max=1. I.e. if it dies it automatically restarts.
  • Every night a Lambda creates a snapshot of the instance as a new AMI and updates the ASG Launch Configuration with the new AMI ID. I.e. if the instance dies the next day it will be spun up from the last night's snapshot.

This works well for instances that don't change very often. E.g. our CMS has all the data in a database and all the app config and user files on EFS and only some packages and system config files are updated on the instance from time to time, but not very often.

May something like that work for you? However the effort to implement that is quite likely higher than migrating to EFS in the first place and the result is not as good and as resilient either.

Hope that helps :)