---
layout: article
title: Functions
description: Learn what an Appwrite Function can do for you and how to create a new Appwrite Function
---

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](/docs/products/functions/runtimes).

Each time a function's code is updated, a [deployment](/docs/products/functions/deployments) 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](/docs/products/functions/deploy-from-git).
You can also switch between different deployments by activating them.

# Create function
You can create Appwrite Functions in three different ways.

**Git**

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](/images/docs/functions/template.avif)

**Manual**

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.

```text
.
├── package.json
└── index.js
```

Package your code files into the `.tar.gz` format. **Don't include your dependencies folder**, such as `node_modules`.

  ```bash
  tar --exclude code.tar.gz -czf code.tar.gz .
  ```
  ```cmd
  tar --exclude code.tar.gz -czf code.tar.gz .
  ```
  ```powershell
  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.

**CLI**

You can create functions using the CLI without needing to access the Console.

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.

```sh
appwrite init functions
```

To deploy the generated code, add any dependencies and push the function using the following command:

```sh
appwrite push functions
```

[Learn more about the CLI functions commands](/docs/tooling/command-line/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](/docs/products/functions/develop#entrypoint).
It's recommended you use one of the [starter function templates](/docs/products/functions/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](/docs/advanced/billing/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](/docs/advanced/billing/compute#build-timeouts) and the [pricing page](/pricing).

## 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](/docs/advanced/security/permissions#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](/docs/apis/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](https://en.wikipedia.org/wiki/Cron). 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.

[Learn more about scheduled executions](/docs/products/functions/execute#schedule)

## 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](/docs/products/functions/develop#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.

[Learn more about scopes](/docs/partners/project/api-keys#scopes)
