Each Appwrite Function is a piece of developer defined code that can be executed on demand. When you create a new Appwrite Function, you select a name, ID, and runtime language.
Each time a function's code is updated, a deployment is created, which is like a version of a function. Each function has a single active deployment, which is the version of code that's executed when it's called. You can update the Appwrite Function's code by creating new deployments. You can also switch between different deployments by activating them.
Create function
You can create Appwrite Functions in three different ways.
It's recommended to create functions that are connected to version control. This lets you track your code using Git, which makes it easy to integrate Appwrite Functions into your existing code base.
In the Appwrite Console's sidebar, click Functions.
Click Create function.
Connect your project to your Git provider. You will be asked to authorize Appwrite and grant access to some resources necessary for the Git deployments to work.
If you already have a repository containing an Appwrite Function, select it under Connect Git repository. If you need to create a new function, select a Quick start template or search for more templates under All templates.
Follow the wizard to configure your new Appwrite Function.
You can also create Appwrite Functions manually by uploading your code in a zipped file. In the Create Function modal, click create a function manually at the bottom to switch to manual create wizard. You will be asked to upload a zip file with your code.
First, navigate inside the folder that contains your dependency file. For example, when you list the content of your folder for a Node.js function, it will look like this.
.
├── package.json
└── index.js
Package your code files into the .tar.gz format. Don't include your dependencies folder, such as node_modules.
tar --exclude code.tar.gz -czf code.tar.gz .
Upload your .tar.gz file and specify the entry point of your function, in this case index.js. Remember to specify the build commands for your function to install dependencies.
You can create functions using the CLI without needing to access the Console.
Before proceeding
Ensure you install the CLI, log in to your Appwrite account, and initialize your Appwrite project.
To deploy your function with the Appwrite CLI, use the appwrite init functions command to create a starter function and paste your code into the generated file and folder.
appwrite init functions
To deploy the generated code, add any dependencies and push the function using the following command:
appwrite push functions
Learn more about the CLI functions commands
Configuration
Name
You can update the name of your function by navigating to your function > Settings > Name. Update your function's name and click Update. Functions are executed using it's ID, updating name does not affect references to your function.
Runtime
Every deployment of a function uses the same runtime. You can update the runtime of a function by navigating to function > Settings > Runtime. Select a new runtime and click Update.
Redeployment required
This change requires your function to be redeployed to take effect.
Build configuration
You can update the entrypoint file and build settings of your function by navigating to your function > Settings > Configuration.
Redeployment required
This change requires your function to be redeployed to take effect.
The Entrypoint refers to the file imported and executed by the function executor. It must export a valid function entrypoint function. It's recommended you use one of the starter function templates and edit from there.
Under Build settings, you can update your build commands. These are terminal commands that will be executed in the runtime containers in the build step of the deployment process.
Git integration
You can update the entrypoint file and build settings of your function by navigating to your function > Settings > Configuration.
Redeployment required
This change requires your function to be redeployed to take effect.
Under Git settings you can configure the Git repository and branch that your function is connected to.
Build commands and entrypoint are executed relative to the configured Root directory of your Git respository.
By default, Appwrite will create comments in PRs to your connected branch. You can use Silent mode to suppress these comments.
Execution logs
You can enable and disable execution logs for your functions by navigating to your function > Settings > Execution logs In production environments, you can choose to disable execution logs to protect user privacy.
Execute access
You can control who can execute your functions by navigating to your function > Settings > Execute access and granting access to select permission roles.
If this is left empty, no user can execute your function. Server SDKs, scheduled executions, and event function triggers don't require permissions to execute a function.
Events
Functions can be triggered by platform events which reflect changes that occur in your Appwrite project. You can configure events triggers by navigating to your function > Settings > Events.
Schedule
Appwrite supports scheduled function executions. You can schedule executions using cron expressions in the settings of your function. Cron supports recurring executions as frequently as every minute.
You can configure events triggers by navigating to your function > Settings > Schedule.
Here are some cron expressions for common intervals:
Cron Expression | Schedule |
*/15 * * * * | Every 15 minutes |
0 * * * * | Every Hour |
0 0 * * * | Every day at 00:00 |
0 0 * * 1 | Every Monday at 00:00 |
Environment variables
Set static environment variables that will be passed to your function by navigating to your function > Settings > Environment variables.
You can also configure global variables that apply to all your functions in the Settings of your project.
Redeployment required
This change requires your function to be redeployed to take effect.
You can access environment variables inside functions using your runtime language's system methods.
Timeout
You can limit the execution time of your function by navigating to your function > Settings > Timeout. There is a system wide maximum timeout of 900 seconds (15 minutes).
Scopes
You can configure the permission scopes for the function dynamic API key. The dynamic API key is automatically generated to access your project resources like users and buckets but can only be used inside of Appwrite functions. Navigate to your function > Settings > Scopes to configure your dynamic API key permission scopes.
Learn more about scopes