Environment variables reference for Compute@Edge
IMPORTANT: The content on this page uses the following versions of Compute@Edge SDKs: JavaScript SDK: 1.3.2 (newer available - latest is 1.5.2, see changes), Rust SDK: 0.9.1 (newer available - latest is 0.9.2, see changes), Go SDK: 0.1.2 (current)
Compute@Edge services can access environment variables provided by the system. All environment variables are strings, though if a variable does not exist, the SDK will behave appropriately. For example, Rust's std::env::var
will return a Result(Err)
.
- FASTLY_CACHE_GENERATION
- FASTLY_CUSTOMER_ID
- FASTLY_HOSTNAME
- FASTLY_POP
- FASTLY_REGION
- FASTLY_SERVICE_ID
- FASTLY_SERVICE_VERSION
- FASTLY_TRACE_ID
Reading and setting environment variables
The values of environment variables are set when a Compute@Edge instance starts running, and do not change during execution. However, environment variables are writable, and will retain any change written to them through the end of the instance lifecycle. Environment variables are scoped to the instance and are destroyed when the instance ends.
- Rust
- JavaScript
- Go
- AssemblyScript
let cache_server_host = std::env::var("FASTLY_HOSTNAME").unwrap_or_else(|_| String::new());
Environment variables in non-production environments
For more information on the availability and values of environment variables in non-production environment, see Testing and debugging.