This topic describes how to use Aliyun Serverless VSCode Extension to create a function.
Provided by Function Compute, Aliyun Serverless VSCode Extension is a VS Code-based development, debugging, and deployment tool that integrates the features of the command-line tool Funcraft and the Function Compute SDK. You can use this extension to perform the following operations:
- Quickly initialize projects and create functions locally.
- Run and debug local functions. The debugging feature is supported in programming languages Node.js, Python, and PHP.
- Pull services and functions from the cloud and run functions in the cloud.
- Deploy services and functions to the cloud and update related configurations.
Step 1: Bind an Alibaba Cloud account to the VSCode extension
- Right-click in the left-side navigation pane, and select Bind New Account to bind an Alibaba Cloud account to the VSCode extension.
- Sequentially enter Account ID, AccessKey ID, AccessKey Secret, and Account Alias (the local account name) of the Alibaba Cloud account.
After the binding is completed, you can view the cloud-side services and functions of the Alibaba Cloud account in the REMOTE RESOURCES pane.You can switch the region in the REMOTE RESOURCES pane to view the services and functions in different regions.
Step 2: Create a function
- Open an empty directory file in the VSCode extension.
- Click the plus sign (+) in the LOCAL RESOURCES pane to locally initialize a Function
- Sequentially enter or select the service name, function name, function runtime, and function type as instructed.
After you specify these parameters, the extension automatically creates a function and displays the created local service and function in the LOCAL RESOURCES pane.
Step 3: Locally debug the function
- If you want to debug functions that run in Python 2.7 or Python 3 runtimes, you must first install the Python extension.
- If you want to debug functions that run in PHP runtimes, you must first install the PHP Debug extension.
- In the LOCAL RESOURCES pane, click the Debug icon on the right of the function name
or the debugging link in the
Handlerfile to locally debug the function.
- Insert a breakpoint into the code and start debugging. The debugging information will
The extension creates the
event.datfile under the directory that stores the function handler file. You can modify the event.dat file to configure events to be triggered each time the function is debugged.
Step 4: Locally call the function
Handlerfile to locally call the function.
event.datfile under the directory that stores the function handler file. You can modify the event.dat file to configure events to be triggered each time the function is called.
Step 5: Deploy the service and its functions
- Click the Deploy icon in the LOCAL RESOURCES pane to deploy the local service and
its functions to the cloud.
- After the deployment is completed, click the Refresh icon in the REMOTE RESOURCES
pane to query the services and functions that are deployed to the cloud.
Step 6: Execute the function in the cloud
The extension creates the
event.dat file under the root directory of your project. You can modify the
event.dat file to configure events to be triggered each time the function is called in the
Step 7: Test the function in the cloud
You can log on to the Function Compute console to check whether the preceding deployment is successful.
- Log on to the Function Compute console.
- In the left-side navigation pane, click Service/Function.
- In the Function Compute Console, find and click the demo service. On the Functions tab, click the testFunc01 function.
- On the page that appears, click the Code tab. On the Code tab, click Invoke to execute the function in the Function Compute console.
Step 8: View execution logs of the function
You can view the execution log on the current page after each execution. To view historical execution logs, click the Log tab. You must configure a Logstore for the function first. For more information, see Logs.