DEV Community

Cover image for Deploying Functions Just Got Easier with Appwrite CLI 2.0!
Christy Jacob for Appwrite

Posted on

Deploying Functions Just Got Easier with Appwrite CLI 2.0!

Appwrite 0.13 was just released and one of the biggest highlights this time around is the brand new Appwrite CLI! The CLI underwent a major overhaul including a complete rewrite in Node.js, easier creation and deployment of cloud functions, the ability to manage your Appwrite projects, collections, CI support and a lot more!

In this article we’ll cover how you can get started with the Appwrite CLI and be on your way to deploying cloud functions!

What is Appwrite you may ask?
Appwrite is open source backend-as-a-service that abstracts all the complexity involved in building a modern application by providing you with a set of REST APIs for your core backend needs. Appwrite handles user authentication and authorization, databases, file storage, cloud functions, webhooks and much more! If there is anything missing, you can extend Appwrite using your favorite backend language.

⚙️ Installation

We’ve made sure developers have multiple installation options from an npm package to standalone binaries and even a Homebrew package.

If you have npm installed, it's pretty simple

npm install -g appwrite-cli
Enter fullscreen mode Exit fullscreen mode

Appwrite Install

Instead if you prefer the standalone binary, you can install the CLI on Linux and MacOS using

curl -sL https://appwrite.io/cli/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

Please note that the binary method of installing the CLI does not work with macOS on ARM.

If you’re on a Windows system, we’ve got something for you as well!

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

If Homebrew is your thing, we have you covered too!

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

With installation now complete, it's time to verify your installation

appwrite -v
0.0.15
Enter fullscreen mode Exit fullscreen mode

This will print the latest version of your CLI.
Getting Started
Before you can start using the CLI, you need to login to your Appwrite account with:

appwrite login
? Enter your email test@test.com
? Enter your password ********
? Enter the endpoint of your Appwrite server http://localhost/v1
✓ Success
Enter fullscreen mode Exit fullscreen mode

You’ll be prompted to enter your email, password and the endpoint of your Appwrite server. If you’re running Appwrite locally, you can use the default value for the endpoint in the prompts.

The CLI is designed to work with multiple Appwrite projects and you can configure the CLI to connect to your project using:

appwrite init project
Enter fullscreen mode Exit fullscreen mode

You can choose to create a new project or connect to an existing one associated with your account. The init project command creates a new appwrite.json file in the current directory with all the information about your current project like the ID, name, collection and function definitions and so on.

You’re now all set to interact with the Appwrite CLI!

⚡️ Deploying Functions

One of the major highlights of the CLI are the new Function starters and easier ways to deploy the cloud functions. You can get started with your first cloud function using:

appwrite init function
? What would you like to name your function? My Awesome Function
? What runtime would you like to use? Node.js (node-17.0)
✓ Success
Enter fullscreen mode Exit fullscreen mode

This command creates a new cloud function on your Appwrite server, and also clones some starter code to help you get going quickly. The starter code is designed to be simple enough to help you get started writing your own functions while being extensive enough to cover most common use cases like dependencies and accessing environment variables. Feel free to examine the code that was just created.

Great! All that’s left now is to deploy your cloud function! Head back to your CLI and use:

appwrite deploy function
? Which functions would you like to deploy? My Awesome Function (6221eff3e289b17042b8)
ℹ Info Deploying function My Awesome Function ( 6221eff3e289b17042b8 )
✓ Success Deployed My Awesome Function ( 6221eff3e289b17042b8 )
Enter fullscreen mode Exit fullscreen mode

Follow the prompts and if everything goes well, your function should now be deployed! You can then head to the Functions section in the Appwrite console and execute your function.

Deploy Function

⬆️ Deploying Collections

The CLI also serves a similar utility with your collection definitions. You can pull all your projects’ collection definitions into your appwrite.json file which you can later use to deploy to a different Appwrite project or server.

appwrite init collection
ℹ Info Found 1 collections
ℹ Info Fetching Millenium Problems ...
✓ Success
Enter fullscreen mode Exit fullscreen mode

If you’re migrating to a new server, be sure to create a new Appwrite project and update the values of projectId and projectName in the appwrite.json file. Don’t forget to update your server endpoint using:

appwrite client --endpoint https://endpoint.com/v1 
Enter fullscreen mode Exit fullscreen mode

And also login to the CLI using your new server’s credentials using the appwrite login command.

Once the CLI is configured to connect to your new project, you can use the deploy command to create all your collection definitions to the server.

appwrite deploy collection
Enter fullscreen mode Exit fullscreen mode

👩‍💻 Usage

In the following section, we’ll cover the usage instructions of some common tasks.

You can create a new user using:

appwrite users create --userId "unique()" --email hello@appwrite.io --password very_strong_password
Enter fullscreen mode Exit fullscreen mode

To list users in your project, you can use the following command:

appwrite users list
Enter fullscreen mode Exit fullscreen mode

Oops. Looks like we forgot to give our first user a name! You can update user information using:

appwrite users updateName --userId 6222455985f1c3d14b35 --name "Awesome User"
Enter fullscreen mode Exit fullscreen mode

Let’s take a look at our users now.

Users List

If you wish to parse the response further, you can print it in a more parser friendly JSON format using the –json flag.

appwrite users list –json
Enter fullscreen mode Exit fullscreen mode

Users List JSON

If you plan to use the CLI in a CI environment, you need to authenticate using an API key. This can be done with the appwrite client command. Everything else remains the same.

appwrite client –key <YOUR_API_KEY>
Enter fullscreen mode Exit fullscreen mode

The CLI also ships with a handy –verbose flag that displays a more detailed error message in case you’re trying to debug something.

The CLI is basically a reflection of the Appwrite API, so any methods you expect in the SDKs should be present as commands in the CLI. At any point, if you need to explore a command, you can do so using the help command or its variants.

appwrite users
appwrite users -h
appwrite users –help
appwrite users help
Enter fullscreen mode Exit fullscreen mode

Users Help

🤩 What's next?

We’ll continue to iterate on community feedback and be back with even better versions of the CLI packed with a lot more features! Eventually, the CLI will become the only tool you’ll need to install, migrate, manage and monitor your Appwrite server.

Meanwhile, we’d love you to check it out and share your valuable feedback and hang out with us on our Discord. If you like what we do at Appwrite, don’t forget to drop us a tiny star on GitHub. It means a lot.

Top comments (2)

Collapse
 
gevera profile image
Denis Donici

Awesome update! Keep it up!

Collapse
 
mc-stephen profile image
Stephen Michael

Nice article, pls i would i appreciate if this article is going to be updated if anything in the appwrite cli changes.