Functions

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.

    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 ExpressionSchedule
    */15 * * * *Every 15 minutes
    0 * * * *Every Hour
    0 0 * * *Every day at 00:00
    0 0 * * 1Every 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