DEV Community

Cover image for Appwrite Functions: The Ultimate Guide to deploy serverless functions with Appwrite Cloud
Navdeep Mishra
Navdeep Mishra

Posted on • Updated on

Appwrite Functions: The Ultimate Guide to deploy serverless functions with Appwrite Cloud

Hey everyone, Today we'll see how we can deploy our own Appwrite function with Appwrite Cloud within minutes. It's so easy and useful.

So for getting started first create your account here - Appwrite Cloud

'appwrite cloud home'

After signup create a project, click on Functions as shown below -

'Appwrite functions'

After this there are two ways to deploy it.

Method 1 - Appwrite CLI

Appwrite provide a featured packed CLI for managing your Appwrite projects. This is a one time process and helps a lot in deploying your functions easily.

  • Install the Appwrite CLI -


npm install -g appwrite-cli


Enter fullscreen mode Exit fullscreen mode

or dependency free installation

For Mac


brew tap appwrite/sdk-for-cli https://github.com/appwrite/sdk-for-cli
brew update
brew install --HEAD appwrite


> For windows 
Enter fullscreen mode Exit fullscreen mode

iwr -useb https://appwrite.io/cli/install.ps1 | iex


> For Linux
Enter fullscreen mode Exit fullscreen mode

curl -sL https://appwrite.io/cli/install.sh | bash


- After the installation is complete, verify the install using

Enter fullscreen mode Exit fullscreen mode

appwrite -v


- Now, Login to the appwrite cli. This will ask for your email and password. If you logged in with social auth try password reset and set a password first.

Enter fullscreen mode Exit fullscreen mode

appwrite login



!['Appwrite login'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48y13noe32pjd917p5zp.png)

- After this, verify that you can access your project - 

Enter fullscreen mode Exit fullscreen mode

appwrite projects get --projectId [PROJECT_ID]


- Now our appwrite cli setup is complete and now let's set up our function.

> Now we have to connect our existing project first. Run


Enter fullscreen mode Exit fullscreen mode

appwrite init project

- Select the existing project and after that you'll see result like this in your console.


!['appwrite project init'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f46uybzmytf9nj4onmi7.png)

- Now run below command to initialize your project.

Enter fullscreen mode Exit fullscreen mode

appwrite init function


!['appwrite init function image'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4irzjew68o2rcuotrout.png)

- Now here you have to select your runtime. If you want to deploy a javascript function then select _node runtime_. I have selected _node runtime_ here.

**_After selecting this our function is created_**.

!['appwrite function directory image'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pes8jwp8t2amhtn85tqn.png)

- Update `src/index.js` with your function code. For detailed information about functions visit [here](https://appwrite.io/docs/functions).

- Once you have updated your code then

Enter fullscreen mode Exit fullscreen mode

appwrite deploy function

- Select your function with `arrow keys` and confirm with `space` and hit 'enter'.

**Congratulations** 🎊🎊🎊 _Your Appwrite function is deployed successfully in Appwrite Cloud.
Now visit your functions dashboard, open the function you deployed just now. Go to settings tab and change the execution policies according to your need. Now Execute the function on event or add custom schedules for execute from your code. You can check function execution in the function dashboard by clicking on `Execute` button._

**Method 2 - Appwrite Cloud**

- Login to your Appwrite cloud account and navigate to functions page.

- Click on _create function_ button and enter necessary details.

!['Create function appwrite cloud'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1k2n91n6mgy6ktl39oi.png)

- In the next optional steps you can add _Events_, _Execute Access_, _Schedule_ and _Variables_ for your Appwrite function and then hit _Create_

**_Your Appwrite function is created._** πŸ”₯

Wait .......................... πŸ€”πŸ€”πŸ€”πŸ€”
We have to add code as well right?....
So let's proceed then..

- After creating your function you should see this screen.

!['appwrite function'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/psl5pf1v5vwuih35xfer.png)

- Now just pick your `index.js` file (with all code) and `package.json` and create a `tar.gz` compressed file. You can use **7zip** if you are in windows platform.

- Once you have create `tar.gz` compressed file. Go to function dashboard and click on **Create Deployment** and upload this `tar.gz` file like shown below and mention `index.js` as the entry point.


!['uploading the tar.gz files'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d337asp1j4cfbzyvx7fh.png)
- Also check the **Activate deployment** checkbox to activate function after deployment.

**Congratulations** 🎊🎊🎊 _Your Appwrite function is deployed successfully in Appwrite Cloud.

- Once done click on `Execute Now` button and you'll see this.

!['Function executed successfully'](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1yxxea30yau2fc7t92tn.png)

_You can check logs where you can find all error logs, console logs or response returned by your Appwrite function._

_That's all, You have successfully learned how to deploy Appwrite function.

Thankyou for reading thisπŸ˜‰
Please like πŸ’“, share 🌐 and follow πŸ™β€β™‚οΈ for more useful content._

Navdeep M.























Enter fullscreen mode Exit fullscreen mode

Top comments (0)