I triggered an auto scaling group (from launch configuration) with a customised Debian9 image in AWS where I have preinstalled software packages like Apache, Memcache, Chrony along with PHP code base and other required packages. This just works fine until I change the PHP codebase. Everyday at least once PHP codebase is modified manually on the server.
Whenever auto scaling is triggered based on the pre-defined metrics(like memory load, cpu and so on) I would like to spin up one more server. This newly created server must have those updated code base so that both servers are in sync.
Question: How can that be achieved without just copying files from one server to another when the second server goes up and running?
One way could be copying the files from /var/www/* using rsync from old server to the newly created server. I believe this not the best solution to do it. Taking snapshots in each hour is not an option since it will increase the operational costs.
What would be the best way to update the custom image whenever php codebase changes? Could someone suggest/recommend me the best way to do? I believe in this community there are experts who have done similar kind of stuff in AWS.