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
Enter fullscreen mode Exit fullscreen mode

For windows

iwr -useb https://appwrite.io/cli/install.ps1 | iex
Enter fullscreen mode Exit fullscreen mode

For Linux

curl -sL https://appwrite.io/cli/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
  • After the installation is complete, verify the install using
appwrite -v
Enter fullscreen mode Exit fullscreen mode
  • 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.
appwrite login
Enter fullscreen mode Exit fullscreen mode

'Appwrite login'

  • After this, verify that you can access your project -
appwrite projects get --projectId [PROJECT_ID]
Enter fullscreen mode Exit fullscreen mode
  • 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

appwrite init project
Enter fullscreen mode Exit fullscreen mode
  • Select the existing project and after that you'll see result like this in your console.

'appwrite project init'

  • Now run below command to initialize your project.
appwrite init function
Enter fullscreen mode Exit fullscreen mode

'appwrite init function image'

  • 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'

  • Update src/index.js with your function code. For detailed information about functions visit here.

  • Once you have updated your code then

appwrite deploy function
Enter fullscreen mode Exit fullscreen mode
  • 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'

  • 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'

  • 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'

  • 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'

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.

Top comments (0)