We are running our Magento store on AWS and we have autoscaling setup behind an ELB. At any time, we have at least 2 web servers running. Each web-server instance has it's own Varnish Cache server in front of it handling incoming requests.
Now, the problem is once we change some static content like CSS, Images etc., we have to SSH into each frontend EC2 Instance and ban the cached objects from Varnish. This is really troublesome as we first have to get the IPs of the instances manually from the AWS Console and then SSH into them which takes a lot of time and not very efficient if we have more than 2-3 servers at any time.
I looked into installing PageCache extension by Phoenix Media but the problem with their module is that we still have to manually enter a static list of IPs of varnish instances in the configuration which we don't know beforehand. This won't work in our case because the autoscaling servers come and go.
Is there a way that I can setup cache invalidation for all the running frontend servers at once? I have added the required piece of code in default VCL file which allows purging/ban from any instance in the same subnet. For all admin tasks, we have a dedicated EC2 and I plan to use the same to issue cache invalidation requests to all the frontend servers.
I was thinking, may be I could write a shell script and get the list of IPs of all frontend instances using AWS API and issue the ban command to all of them. Will this work? How to get it setup?
Also, can something be done to automate the cache invalidation of all the files which got changed during the latest code pull from repository?
What would be the most efficient way to work around this?