I am wondering how I can dynamically increase and decrease the number of varnish instances for a Magento2 installation as needed - with an aws autoscaling group, for example.

Configuring them from the client side is easy: I can just use a load balancer. But Magento2 also needs to be aware of each instance, and this seems to be a bit more tricky. Updating the configuration file would require an app:config:import, which is a bit of a hassle in a production multi-server environment.

The Magento documentation suggests this command:

magento setup:config:set --http-cache-hosts=,


Is it an appropriate way to update the varnish servers continuously in an operational / live / production system?

1 Answer 1


The best way that I've found to do this is to write a PHP script that utilizes the AWS PHP SDK to get a list of all the current instances of your auto-scaling group:


That PHP script can then use the command you mentioned on all the production instances. I don't believe there's any better way to do it than that, and has been used in production instances with success.

  • Sounds good! - Do you know if the command can be run in a production system without any negative impact?
    – hey
    Jan 17, 2019 at 1:10
  • 1
    Yes, absolutely. :) Of course, always test things on staging, it never hurts! Jan 17, 2019 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.