Back

How to move Function Environment Variables from local to server

  • 0
  • Functions
  • Web
shofol
16 Mar, 2023, 08:21

I have deployed some functions from my local appwrite instance to server appwrite instance. But, when I deployed the environment variables of the functions I created on my local machine weren't moved to the server.

Now, what should I do? Manually add these variables again through console? Or, do we have any config or env file where I can add those and upload to server?

I have multiple environment variables for each functions. So, it's really annoying to write the variables every time I deploy to the server or reconfigure the server.

TL;DR
To move Function Environment Variables from local to server: 1. The `appwrite.json` file should be present in your web app folder. On the server, there is no need for the `appwrite.json` file. 2. Check your Appwrite CLI version by running `appwrite --version`. 3. If you have multiple servers, you can change the credentials in the `env.py` file instead of having to run `appwrite logout` and `appwrite login` every time. 4. You can automate the deployment of collections, attributes, indexes, and functions using the repository found at this link: [https://github
Meldiron
16 Mar, 2023, 08:39

Hey there 👋 When you deploy a function (appwrite deploy function), it does not read your .env file.

Deployment of a function does not touch your variables, by default.

To make deployment update your variables, you can specify variables key in definition of your function in appwrite.json. Keep in mind, this will overwrite ever variable currently configured on the function, and only apply those in appwrite.json. Keep in mind this will result in you storing secrets inside appwrite.json. So make sure to NOT push this to your version control such as git, otherwise you are creating security vulnerabilities.

shofol
16 Mar, 2023, 10:48

Can you share an example appwrite.json? And, do you have this info in your documentation?

Meldiron
16 Mar, 2023, 10:50

I dont have any example project with variables in appwrite json :/ Tho it would look something like this:

TypeScript
{
    "projectId": "almostGist",
    "projectName": "Almost Gist",
    "collections": [],
    "functions": [
        {
            "$id": "toggleReaction",
            "name": "toggleReaction",
            "runtime": "node-16.0",
            "path": "functions/toggleReaction",
            "entrypoint": "src/index.js",
            "ignore": [
                "node_modules",
                ".npm"
            ],
            "execute": [
                "users"
            ],
            "events": [],
            "schedule": "",
            "timeout": 15,
            "variables": {
                "MAX_ALLOWED_REACTIONS": "5"
            }
        }
    ]
}

Docs: https://appwrite.io/docs/command-line-deployment#function-options

shofol
16 Mar, 2023, 10:51

Great, thanks

shofol
18 Mar, 2023, 17:21

Hi @Meldiron , I tried your method but it's not working unfortunately. And, when I'm deploying the function on server, the appwrite.json on the server is not updating. Am I missing something here?

rafagazani
18 Mar, 2023, 18:45
rafagazani
18 Mar, 2023, 18:46

This repository aims to facilitate the deployment of an appwrite project. In it you will find a way to send collections, attributes, index and functions in an automated way.

rafagazani
18 Mar, 2023, 18:51

the cool thing is that if you have more than one server, just change the credentials in the env.py file. It was very annoying to run appwrite logout login when you have more than one server

Meldiron
18 Mar, 2023, 18:57

What Appwrite CLI version do you have? appwrite --version

shofol
18 Mar, 2023, 19:00

1.2.1. I tied again, now the variables are copied but appwrite.json on the server is not updated yet. Is this an expected behavior?

Meldiron
18 Mar, 2023, 19:00

appwrite.json should live in your web app folder. On server, there is no need for appwrite.json.

shofol
18 Mar, 2023, 19:01

Ok

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