Getting Fastly service ID in VCL


Is there a way to programatically get the Fastly service ID in VCL, so VCL code can be reused between services?

I have currently created a header in the Fastly UI that contains the service ID, but this seems like a bit of a hack :neutral_face:


The variable req.service_id will return the Fastly service_id. For instance, if you are using a custom logging format in your vcl, you can set the call to your format:

log {"syslog "}req.service_id{" my_logging_endpoint_name :: "}

You can then use the same vcl within different services.


@cassandra Brilliant, thanks! I looked everywhere for that and couldn’t find it.