Azion CLI quickstart
Install the Azion CLI, create a JavaScript function project, run it locally, and deploy it to Azion from your terminal.
This guide instructs you through your first deployment with the Azion CLI.
- Install the CLI and save your personal token in it.
- Create a JavaScript function project with
azion init. - Run the function on your machine with
azion dev. - Deploy the function with
azion deployand request it over HTTPS.
The azion deploy command creates five objects from the project, and each one links to the next:
- The function holds the code in
src/function/index.js. - The function instance binds the function to the application.
- The application carries a request rule,
Execute Function, that runs the instance on every path. - The workload serves the application on a domain.
- The deployment connects the workload to the application.
For more information about functions, refer to Functions.
Prerequisites
- An Azion account. To create one, refer to Create an account.
- A personal token. To create one, refer to How to manage a personal token. The CLI also manages tokens with Azion CLI personal-token.
- Node.js and npm. The CLI runs the Azion bundler with
npxto build the project.
Install the CLI and log in
Install the Azion CLI with the install script:
If you use Homebrew, install the azion formula instead:
Either command puts the azion binary on your path. Confirm the installed version:
The command prints the version:
Save your personal token in the CLI. Replace [TOKEN VALUE] with your token:
The CLI stores the token locally, and later commands use it without the flag. Confirm the account the CLI uses:
The command prints the client ID and email of the account, and the active profile:
The CLI is installed and authorized on your account.
Create the project
The azion init command creates the project from a preset and a template. Create a project named my-function:
Without --name, the command asks for the name and suggests a random one. The command then asks five questions. Answer them in this order:
At ? Choose a preset:, use the arrow keys to select Javascript.
At ? Choose a template:, select Hello World.
At Do you want to install project dependencies?, enter Y.
At Do you want to start a local development server?, enter n. azion dev starts it later.
At Do you want to deploy your project?, enter n. azion deploy deploys it later.
The command fetches the template, installs the dependencies, and confirms the project:
The project is in a new my-function directory, with these files:
The template writes the function to src/function/index.js. It answers every request with Hello World!:
Replace the contents of src/function/index.js with the following code. The function then returns the path and method of each request as JSON:
The my-function project holds the function code and is ready to run.
Run the function locally
The dev, build, and deploy commands run from inside the project directory. Go to the my-function directory:
Start the local development server:
The command builds the function and serves it on port 3333:
The server keeps the terminal busy. In a second terminal, request a path from the server:
The function answers with a JSON body:
The function runs on your machine and returns the path and method of the request.
Deploy the function
The azion deploy command uploads the project, builds it, and creates the function, the application, and the workload. From the my-function directory, deploy the project:
The command prints the domain of the workload:
The deploy records the ID of each object it created in azion/azion.json. Later deploys read this file to update the same objects:
The first deploy can take several minutes to answer from every location. Until a location has the function, it answers 404 with a page titled There's nothing here yet. Wait and retry before you diagnose the deploy.
Check the deployed function
Request the same path from the domain that azion deploy printed. Replace <your-azion-domain> with that domain:
The function answers with the same JSON body it returned on your machine:
The function runs on Azion’s distributed infrastructure and answers on the workload domain.
To change the function, edit src/function/index.js and run azion deploy again from the my-function directory. Later deploys take about two minutes to answer from every location.