Deploying Functions Just Got Easier with Appwrite CLI 2.0!
Christy Jacob
Posted on March 11, 2022
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
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
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
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
With installation now complete, it's time to verify your installation
appwrite -v
0.0.15
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
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
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
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 )
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.
⬆️ 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
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
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
👩💻 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
To list users in your project, you can use the following command:
appwrite users list
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"
Let’s take a look at our users now.
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
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>
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
🤩 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.
Posted on March 11, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.