Skip to content

Functions

Functions_

Learn what an Appwrite Function can do for you and how to create a new Appwrite Function

6 min read

Raw

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.

  1. In the Appwrite Console's sidebar, click Functions.
  2. Click Create function.
  3. 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.
  4. 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.
  5. Follow the wizard to configure your new Appwrite Function.

Create project screen
Create project screen

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.

Build configuration

You can update the entrypoint file and build settings of your function by navigating to your function > Settings > Configuration.

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.

Resource limits

Under Settings - Resource limits, you can set build and runtime specifications independently. The build spec applies while your deployment is being built and packaged; the runtime spec applies to each function execution. Both use the same CPU and memory tiers on Cloud. This lets you align compute with heavy dependency installs or compilation without over-provisioning every invocation.

On Appwrite Cloud, customizing specifications requires the Pro plan. See Compute for tiers, GB-hours, and pricing.

Build timeout

On Appwrite Cloud, the build phase of each deployment must complete within your plan’s maximum build duration (for example, 15 minutes on Free and 45 minutes on Pro and Scale). See Build timeouts and the pricing page.

Git integration

You can update the entrypoint file and build settings of your function by navigating to your function > Settings > Configuration.

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 can run your function on a recurring schedule. Configure it by navigating to your function > Settings > Executions > Schedule, and choose one of two options:

  • Interval: run every N minutes. It works like cron where Appwrite picks the time for you: an hourly interval runs at the same point in every hour, such as 37 minutes and 21 seconds past, chosen for your function. Use it when the function needs to run regularly but not at an exact time, such as syncing data or cleaning up records.
  • Cron: run at the times in a cron expression. Use it when the time of day matters, such as a report at 09:00 every Monday.

A function uses an interval or a cron expression, not both. Both run as often as every minute, except intervals on the Appwrite Cloud Free and Education plans, which start at 60 minutes.

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 ephemeral API key. The ephemeral 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 ephemeral API key permission scopes.

Was this page helpful?

Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.