Environment variables reference for Compute@Edge

IMPORTANT: The content on this page is written for version 0.8.0 of the fastly crate. If you have previously used this example, your project may be using an older SDK version. View the changelog to learn how to migrate your program.

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).

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.

  1. Rust
  2. JavaScript
  3. AssemblyScript
let cache_server_host = std::env::var("FASTLY_HOSTNAME").unwrap_or_else(|_| String::new());