Set the Environment Variable

Environment variables allow defining dynamic values that are external to the code but are accessible to the function during runtime. These variables are set outside the function code and can be modified without changing the code itself, providing flexibility and security. They are commonly used to store configuration settings, sensitive data or credentials, or any other information that the function may need to operate.

  1. Click + Add Environment variable.
    Figure 1.


  2. If you are using environment variables, include the following in your code:
    • Python:
      import os
      var_name = os.environ["var_name"]
      
    • GO:
      package function
        
      import (
        "io/ioutil"
        "net/http"
        "os"
      )
         
      // Handle a function invocation
      func Handle(w http.ResponseWriter, r *http.Request) {
          varName := os.Getenv("var_name")
         
          // ...
      }
      
    Note: The environment variables are type string, so include the appropriate changes if you want to define them as any other type (number, object…)