A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions). It supports quick creation of edge functions, local debugging, version publishing and deployment, and trigger management.
English | 简体中文
Note: ESA CLI is in public beta. If you encounter any issues or have any suggestions while using it, please feel free to submit an issue or a pull request.
We are actively working to improve this tool and welcome any feedback. Thank you for your understanding and support!
Install and run the CLI using npm:
$ npm install esa-cli -g # Install globally
$ esa -v # Check the version
& esa init
The initialization command has a complete process guide. Follow the prompts to enter the project name and choose a template.
Local dev is the core feature of the CLI, offering a more convenient debugging experience compared to the Alibaba Cloud ESA console.
& cd <Project Name>
& esa dev [options]
In an EdgeRoutine project, the entry file is src/index.js
, and the basic structure is as follows:
const html = `<!DOCTYPE html>
<body>
<h1>Hello World!</h1>
</body>`;
async function handleRequest(request) {
return new Response(html, {
headers: {
'content-type': 'text/html;charset=UTF-8'
}
});
}
export default {
async fetch(event) {
return event.respondWith(handleRequest(event));
}
};
For more EdgeRoutine APIs and syntax, please refer to the API Reference
After executing esa dev
, the entry file will be automatically packaged and a local debugging service will be started. The interface looks like this:
- Press
b
to open the debugging page in the browser. - Press
d
to view debugging instructions. Chrome does not allow the command line to open the debugging page. - Open
chrome://inspect#devices
in the Chrome browser to see a running Remote Target. Click inspect below it to view console information. Note that the EdgeRoutine code is server-side, so the console on the preview page will not output console in the entry file. Use inspect for debugging. - Press
c
to clear the panel. - Press
x
to exit debugging. - You can use
esa dev --port <port>
to temporarily specify the port or useesa config -l
to set the port by project configuration.
You need to log in to your Alibaba Cloud account to perform remote management operations.
First, visit the Alibaba Cloud RAM Console to get your AccessKey ID and AccessKey Secret, then execute esa login
and follow the prompts to enter them.
& esa login
& esa logout
After local debugging is complete, you need to create a code version for deployment.
& esa commit # Create a Version
After the code version is created, it needs to be deployed to edge nodes.
Use the esa deployments [script]
command to manage versions and deployments.
& esa deploy # Deploy versions to the target environment
& esa deployments list # View deployments
& esa deployments delete <versionId> # Delete a version
Note: Deployed versions cannot be deleted.
Once deployed to the nodes, you can configure triggers to access your edge functions. There are two types of triggers:
- Domain: After you associate the routine with a domain name, you can use the domain name to access the routine.
- Route: After you add a route for requested URLs, the routine is called from the edge to respond to the request.
& esa domain list
& esa domain add <domainName>
& esa domain delete <domainName>
& esa route list
& esa route add [route] [site]
& esa route delete <route>
You can view and delete Routine functions through the CLI.
& esa routine list
& esa routine delete <routineName>
see Commands
endpoint = "" # ESA API Endpoint
lang = "zh_CN" # language
[auth]
accessKeyId = "" # AccessKey ID
accessKeySecret = "" # AccessKey Secret
name = "Hello World" # Project name
description = "Hello World" # Project description
entry = "src/index.js" # Entry file
codeVersions = [ ] # Code version
[dev]
port = 18080 # Debug port
localUpstream = '' # When debugging locally, the upstream source site will replace the current origin when returning to the source