Aliyun Serverless VSCode Extension is a graphic development, debugging, and resource management tool for Function Compute. This extension is developed based on Visual Studio Code (VS Code). This topic describes the commonly used features of Aliyun Serverless VSCode Extension and how to use Aliyun Serverless VSCode Extension to create functions.
Prerequisites
- VS Code: Download VSCode from the Visual Studio Code official website.
- Docker: For information about how to download and configure this component, visit alibaba/funcraft.
Background information
Aliyun Serverless VSCode Extension is a VS Code-based development, debugging, and deployment extension provided by Function Compute. This extension integrates the features of Function Compute SDKs and Funcraft, a command-line tool provided by Function Compute. For more information, see Supported SDKs and visit Aliyun Serverless VSCode Extension and Funcraft. You can use this extension to perform the following operations:
- Initialize projects and create functions in your local environment.
- Run and debug local functions, and deploy the local functions of your services to Function Compute.
- View services, functions, and the configurations of the services and functions, and invoke functions in Function Compute.
- Obtain syntax prompts of template files, including automatic completion, schema validation, and hovering prompts.
Install Aliyun Serverless VSCode Extension
- Start VS Code and go to the extension marketplace.
- Search for Aliyun Serverless, view the details, and install the extension.
- Restart VS Code. The icon for Aliyun Serverless VSCode Extension is displayed in the left-side navigation pane.
Quick start
- Bind an Alibaba Cloud account.
- In the left-side navigation pane, click the icon for Aliyun Serverless VSCode Extension. Then, click Bind New Account.
- Enter your Alibaba Cloud account, the AccessKey ID, the AccessKey secret, and the on-premises name of the account. After the account is bound, you can view the services and functions of the account in Function Compute.You can click the More icon in the upper-right corner of the Remote Resources list. Select Switch Region from the drop-down list to view services and functions in different regions.
- Create a function.
- Open an empty directory file in VS Code. In the LOCAL RESOURCES list, click the Create Function icon to initialize an on-premises Function Compute project.
- Specify the service name, function name, runtime, and function type. After you configure the parameters, Aliyun Serverless VSCode Extension automatically creates the function. The new on-premises service and function are displayed in the LOCAL RESOURCES list. You can also click the Create Function icon next to a service in the LOCAL RESOURCES list to create functions for the service. Follow the on-screen instructions to enter or select the function name, function runtime, and function type.
- Deploy services and functions.
- In the LOCAL RESOURCES list, click the Deploy icon to deploy on-premises services and functions to Function Compute. After you deploy the services and functions, click the Refresh icon in the REMOTE RESOURCES list to view the services and functions that are deployed to Function Compute.
- In the LOCAL RESOURCES list, click the Deploy icon to deploy on-premises services and functions to Function Compute.
Other features
- Invoke on-premises functions In the LOCAL RESOURCES list, click the Local Run icon next to a function or the link in the handler file to invoke on-premises functions.The logs and invocation results of the functions are displayed on the TERMINAL tab.Aliyun Serverless VSCode Extension creates an event.dat file in the directory in which the function handler file is stored. You can modify the event.dat file to configure events that are triggered when the function is invoked.
- Debug on-premises functions Important
- If you need to debug functions that are run in Python 2.7 or Python 3, you must install the Python extension.
- If you need to debug PHP functions, you must install the PHP Debug extension.
In the LOCAL RESOURCES list, click the Debug icon next to a function or the link in the handler file to debug the on-premises function.Specify breakpoints in the code and start the debugging process. The debugging information is displayed.Aliyun Serverless VSCode Extension creates an event.dat file in the directory in which the function handler file is stored. You can modify the event.dat file to configure events that are triggered when the function is debugged.
- Invoke functions in Function Compute In the REMOTE RESOURCES list, click the Remote Invoke icon next to a function to invoke the function.The logs and invocation results of the function are displayed on the TERMINAL tab.
Aliyun Serverless VSCode Extension creates an event.dat file in the root directory of the project. You can modify the event.dat file to configure events that are triggered when the function is invoked.
- Configure parameters in templates files
Funcraft uses YAML template files to describe serverless applications. For more information, visit Funcraft and YAML. When you use Aliyun Serverless VSCode Extension to create a function, default values are automatically specified for the parameters in the template file. If you need to modify the configurations of an on-premises service or function, click the name of the service or function in the LOCAL RESOURCES list to go to the descriptions in the template file. The description blocks are highlighted and then gradually dimmed.
- Obtain template prompts
- Completion
All keys in the template.yml file are automatically completed based on precise prompts. Precise prompts are provided based on the indentation level.
- Schema validation
All resource configuration information in the template.yml file is validated based on the template specification description. For more information, visit Serverless Application Model.
- Hovering prompts
All resource configuration information in the template.yml file is prompted. In the template.yml file, when you move the pointer over a resource key, a hovering prompt appears which indicates the resource. The hovering prompt shows the fields that you can configure under the resource key, such as the field name and field type.
- Completion