I use Bun 1.1 runtime for Functions and I'd like to use the value of a global environment variable that I have set.
In the Starter example, I can see: Bun.env['APPWRITE_FUNCTION_PROJECT_ID']
When I replace the attribute with the global environment variable key I've set on the project, it returns undefined
SOLUTION
- Copy the Global variables key-value pairs from the Project Settings in Appwrite console by clicking Editor
- Paste the key-value pairs into an
.envcreated at the root directory of your Appwrite function in your codebase. This.envfile is not tracked by default - don't update this behaviour!. - Type
appwrite run function, choose your function and you will now observe that your variables are part of your local Dockerised runtime.
Clarification: I am attempting to run this function locally. The global env var is hosted in Appwrite console.
Alright, I figured this out. Solution to follow in the next reply.
If you are trying to run a function locally and want to access your global environment variables, the way to do this is to perform the following steps:
- Copy the Global variables key-value pairs from the Project Settings in Appwrite console by clicking Editor
- Paste the key-value pairs into an
.envcreated at the root directory of your Appwrite function in your codebase. This.envfile is not tracked by default - don't update this behaviour!. - Type
appwrite run function, choose your function and you will now observe that your variables are part of your local Dockerised runtime.
[SOLVED] How to access global environment variable from function?
Recommended threads
- RowList: The value of total is coming as...
RowList: The value of total is coming as a String, so it throws an error because it’s not parsed into an int. Error: TypeError: \"37\": type 'String' is not a ...
- 408 Timeout / Curl Error 7 in Executor w...
Hey everyone, I am losing my mind over a routing loop/timeout issue on a fresh self-hosted setup. I have a single Linux VPS (IP: 45.141.37.105) and one domain (...
- functions returning error 401 in local
I updated to 1.9.0, and the functions that used to work fine in 1.8.1 are now giving me a 401 error. I can't seem to find a solution. If anyone is running versi...