All Products
Search
Document Center

CloudFlow:Aliyun Serverless VSCode Extension

Last Updated:Oct 30, 2023

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

If you want to use all features of Aliyun Serverless VSCode Extension, make sure that the following components are installed on your on-premises computer:

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

  1. Start VS Code and go to the extension marketplace.
  2. Search for Aliyun Serverless, view the details, and install the extension.
  3. Restart VS Code. The icon for Aliyun Serverless VSCode Extension is displayed in the left-side navigation pane.

Quick start

  1. Bind an Alibaba Cloud account.
    1. In the left-side navigation pane, click the icon_Aliyun_Serverless_VSCode_Extension icon for Aliyun Serverless VSCode Extension. Then, click Bind New Account.
      vscode_bind_account
    2. Enter your Alibaba Cloud account, the AccessKey ID, the AccessKey secret, and the on-premises name of the account.
      vscode_bind_account_toast
      After the account is bound, you can view the services and functions of the account in Function Compute. vscode_bind_account_result
      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. vscode_switch_region
  2. Create a function.
    1. 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.
      vscode_create_function
    2. 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.
      vscode_create_function_result
      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. vscode_create_function_underservice
  3. Deploy services and functions.
    1. In the LOCAL RESOURCES list, click the Deploy icon to deploy on-premises services and functions to Function Compute.
      vscode_deploy
      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. vscode_deploy_result

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. vscode_local_invoke
    The logs and invocation results of the functions are displayed on the TERMINAL tab. vscode_local_invoke_result
    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. vscode_local_invoke_event
  • 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. vscode_local_debug
    Specify breakpoints in the code and start the debugging process. The debugging information is displayed. vscode_local_debug_result

    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. vscode_remote_invoke
    The logs and invocation results of the function are displayed on the TERMINAL tab. vscode_local_invoke_result

    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.

    vscode_goto_template
  • 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.

Feedback

Scan the following QR code to join the official Function Compute DingTalk group for troubleshooting or send your feedback on GitHub. Qr code