1
votes

I have a web app living on AWS elastic beanstalk and I would like to use Varnish in front of my web servers. The problem I'm having is that elastic beanstalk will bring up and bring down instances as traffic requires. Every time an instance is brought down it needs to register with the varnish instance or else varnish will not know to direct traffic to that instance.

Is there some way to subscribe instances to varnish within the elastic beanstalk environment?

1
If anyone is having this same problem, I found this really great blog post detailing a work around. - Loourr

1 Answers

2
votes

OK so I have not used varnish before but I can tell you that with Elastic Beanstalk you can specify that will be run on every instance when before the application is deployed on the instance.

You can create a file .ebextensions/01-register-varnish.config inside your app source directory. Here you can execute custom command, may be a custom script to be executed before the app source is unzipped or after the app source is unzipped.

Example contents of this file:

commands:
  varnish_command: 
    command: <command to run to register with varnish>
    cwd: <working directory>
    env: 
      <variable name>: <variable value>
    ignoreErrors: true

This command will be run every time an application is deployed on the EC2 instance. You can make sure that this command is idempotent so that an instance does not try to register itself twice with varnish.

You can also use container_commands instead of commands in case you want your command to execute after the application source is extracted but before the application is deployed.

Read more about this topic here.