Environment variables API
Environment variables API reference: read the variables and secrets stored on your account from a function with Azion.env.get() or process.env.
The Azion Runtime Environment variables API gives a function the values of the environment variables stored on your Azion account. A variable keeps a configuration value or a secret out of the function code. Use it to connect to a database, a private API, or any other service that asks for credentials. You create and manage variables with Azion CLI, through the azion create variables command and its siblings. For more information, refer to Environment variables.
Access
A function reads a variable with Azion.env.get(), which takes the key of the variable:
On a deployed function, the variables of your account are also properties of process.env:
The env argument of the fetch(request, env, ctx) handler carries no variables on a deployed function: it is an empty object. Read variables with Azion.env.get() or process.env instead.
Parameters
Azion.env.get() takes one parameter.
| Parameter | Type | Description |
|---|---|---|
key | string | Key of the variable to read. |
Return value
Azion.env.get() returns the value stored under the key, as a string. A variable created as a secret, with --secret true, returns its value the same way.
When the key matches no variable on your account, the call returns undefined and throws no error. A call that passes no key also returns undefined.
Example
This function reads the MY_VARIABLE variable and returns its value as plain text, or a fallback string when the variable does not exist:
With MY_VARIABLE set to my-value on your account, a request to the deployed function returns: