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.