Edge Security Acceleration (ESA) provides a command-line interface (CLI) that you can use to manage the full lifecycle of Functions and Pages, debug code, and deploy multi-file features.
Introduction
The ESA command-line interface (CLI) is a tool for managing ESA Functions and Pages. You can use the ESA CLI to perform the following tasks:
Manage the full lifecycle of Functions and Pages locally. This includes creating Functions and Pages, publishing and deploying versions, and managing custom domain names or routes.
Debug functions locally or in an internal network environment. The CLI starts a local debugging service to simulate the online environment for functional testing.
Deploy multi-file projects. The CLI automatically packages and builds project dependencies, such as npm dependencies, and lets you deploy local Node.js projects to the cloud.
Common commands
The ESA CLI provides many commands to manage Functions and Pages. For more information about all commands, see https://github.com/aliyun/alibabacloud-esa-cli.
Command | Description |
init | Select a template provided by ESA to initialize a project. |
dev | Automatically start the local debugging service. |
commit | Commit the project code to the cloud and save it as a version. |
deploy | Deploy a version to all online points of presence (POPs). |
deployments | View the deployment status of the current version or delete a version. |
routine | View all Functions and Pages or delete a function. |
site | View information about all sites under your account. |
domain | Manage domain names attached to Functions and Pages. |
route | Manage routes attached to Functions and Pages. |
login | Log on to your account using an AccessKey ID and AccessKey secret. |
logout | Log off. |
config | Manage the configuration files of the ESA CLI. |
lang | Select the language of the ESA CLI. |
Install Node.js
You must install Node.js before you can use the ESA CLI.
Run the installation command:
yum install nodejs npm.View the installed version:
node -v.
Use the ESA CLI
Use npm to install the ESA CLI. Then, you can view the CLI version and supported commands.
npm install esa-cli -g # Install the CLI globally. esa -v # View the CLI version. esa --help # View CLI commands.Log on to your account. Go to the Alibaba Cloud Resource Access Management (RAM) console to obtain your
AccessKey IDandAccessKey secret. Then, run theesa logincommand. You do not need to log on if you only use the CLI to debug code locally.esa login # Log on esa logout # Log offInitialize a project. Enter the project name, select a template, and follow the prompts to complete the initialization.
esa initDebug your project locally. After you finish coding, run the
esa devcommand. This command automatically packages the entry file and starts the local debugging service.
Press
bin the interface to open the debugging page in your browser.Press
din the interface to view the debugging guide. Note: In Chrome, the debugging page cannot be opened directly from the command line. Instead, open theChrome://inspect#devicespage. You will see a runningRemote Target. Clickinspectbelow the target to view console information. Because EdgeRoutine code is server-side code,consoleoutput from the entry file does not appear in the preview page's console. You must useinspectto debug.Press
cin the interface to clear the panel.Press
xin the interface to exit debugging.Use
esa dev --port <port>to temporarily specify a port.
Generate a version. After you finish debugging locally, generate a code version for deployment.
esa commit # Generate a version.Online deployment: After a version is generated, you can use deployment instructions to deploy it to public cloud POPs.
esa deploy # Follow the prompts to select the version and target environment to deploy. esa deployments list # View the deployment status. esa deployments delete <versionId> # Delete the specified version.Manage custom domain names or routes.
After you deploy to a POP, you must configure a custom domain name or route to access your Functions and Pages:
Domain name: You can attach a domain name to your Functions and Pages. The domain name must be a subdomain of your ESA site. You can use the domain name to directly access the function. In this case, Functions and Pages acts as the origin server for the domain name.
Route: You can attach a route to your ESA site. Accessing the route triggers the execution of Functions and Pages. In this case, Functions and Pages can communicate with the site's origin server.
# Domain name esa domain list esa domain add <domainName> # This must be your domain name that has completed ICP filing. esa domain delete <domainName> # Route esa route list esa route add [route] [site] esa route delete <route>Manage functions.
You can use the CLI to view and delete functions.
esa routine list # View functions. esa routine delete <routineName> # Delete a function.