Back

[SOLVED] Global env variables are not working in functions

  • 0
  • Self Hosted
  • Functions
WhiteWalker72
7 Nov, 2023, 11:56

For some reason my globally defined env variables are not available in my functions. I have tried to:

  • Delete and recreate the variables
  • Restart all containers
  • Use local variables for the functions
  • Redeploy the function But still none of these actions fixed the issue. I'm logging the variables like this:
TypeScript
  const client = new Client()
    .setEndpoint(process.env.APPWRITE_ENDPOINT ?? '')
    .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID ?? '')
    .setKey(process.env.APPWRITE_API_KEY ?? '');

  log(process.env.APPWRITE_ENDPOINT);
  log(process.env.APPWRITE_FUNCTION_PROJECT_ID);
  log(process.env.APPWRITE_API_KEY);

But the output the env variables are all empty strings except for APPWRITE_FUNCTION_PROJECT_ID. I'm using version 1.4.5. I see this issue was posted earlier: https://discord.com/channels/564160730845151244/1146971163403223040 But was not really resolved.

TL;DR
The user is facing an issue where globally defined environment variables are not available in their functions. They have attempted various solutions such as deleting and recreating variables, restarting containers, using local variables, and redeploying the function, but none of these fixed the issue. The user is using version 1.4.5. A previous similar issue was posted but was not resolved.
WhiteWalker72
7 Nov, 2023, 14:30

So I found out that all local variables also don't work in the functions. I looked at the logs of appwrite-worker-builds and I can see that the variables are available when building the function. Not sure if I can do anything else to debug this

ideclon
7 Nov, 2023, 14:58

Where are you defining the variables?

WhiteWalker72
7 Nov, 2023, 15:01

I have defined them globally under Project -> Settings. This used to work but suddenly stopped working since yesterday Defining variables in the functions themselves also does not work anymore

ideclon
7 Nov, 2023, 15:17

I'm unable to reproduce this on either cloud or self-hosted

ideclon
7 Nov, 2023, 15:19

APPWRITE_FUNCTION_PROJECT_ID is generated automatically by Appwrite - there's no need to set it manually. Probably none of your vars are being set.

WhiteWalker72
7 Nov, 2023, 15:20

Yeah I was also thinking that. I don't know enough about the containers to really debug this, would you have any idea?

ideclon
7 Nov, 2023, 15:22

Just to check - you're not seeing any errors, are you?

WhiteWalker72
7 Nov, 2023, 15:39

Usage is causing internal server errors but I don't expect it to be related to this issue

ideclon
7 Nov, 2023, 15:45

Nah, I don't think so. Nothing in the error logs in the Execution?

WhiteWalker72
7 Nov, 2023, 15:58

In the function itself I see this error Error: Unable to connect. Is the computer able to access the url? Which is as expected because the endpoint url is empty

Besides that I see this error in traefik: time="2023-11-07T04:56:11Z" level=error msg="Error while Peeking first byte: read tcp <ip>:80-><ip2>:38894: read: connection timed out" Not sure what traefik is used and if it can relate to my issue

ideclon
7 Nov, 2023, 16:22

Did you replace <ip> and <ip2>? What were they pointing to originally?

Drake
7 Nov, 2023, 17:59

was this function created before 1.4?

WhiteWalker72
8 Nov, 2023, 06:32

At some point I did migrate from v 1.3.x to 1.4.5 but the functions were working fine until 2 days ago. The same issue is happening for newly created functions

WhiteWalker72
8 Nov, 2023, 07:23

Thinking about it I did set the value of _APP_OPENSSL_KEY_V1, this is probably also used to encrypt environment variables. So me setting this value probably caused the issues, could that be the case?

Drake
10 Nov, 2023, 20:21

Yes, if you change the value, all previous encrypted values will no longer be valid

WhiteWalker72
11 Nov, 2023, 08:47

[SOLVED] Global env variables are not working in functions

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more