Aliyun Serverless VSCode Extension is a graphic development, debugging, and resource management extension for Function Compute based on Visual Studio Code (VS Code). This topic describes how to use Aliyun Serverless VSCode Extension to create functions and its common features.

Usage notes

The VSCode plug-in described in this topic is based on Funcraft, which is no longer maintained. If you use Funcraft to manage resources, we recommend that you migrate your resources to Serverless Devs.

For more information about how to migrate Function Compute-related resources from Funcraft to Serverless Devs, see Migrate resources from Funcraft to Serverless Devs.

For more information about Serverless Devs, see What is Serverless Devs?.

We apologize for any inconvenience caused.

Before you begin

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

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. You can use Aliyun Serverless VSCode Extension to perform the following operations:

  • Initialize projects and create functions on premises with high efficiency.
  • Run and debug on-premises functions, and deploy on-premises services and functions to Function Compute.
  • View services and functions, and their configurations 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 your 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 the ID, AccessKey ID, and AccessKey secret of your Alibaba Cloud account, and the on-premises name of the account in sequence.

      You can obtain the ID of your Alibaba Cloud account in the Account Management console and the AccessKey ID and AccessKey secret in the User Management console.

      vscode_bind_account_toast
      Note You can log on to VS Code as a RAM user. If you log on to VS Code as a RAM user, enter the ID of the corresponding Alibaba Cloud account, and the AccessKey ID and AccessKey secret of the RAM user.
      After the account is bound, you can view the services and functions in Function Compute within the account. vscode_bind_account_result
      To view services and functions in different regions, click the More icon in the upper-right corner of the REMOTE RESOURCES list and select Switch Region. vscode_switch_region
  2. Create a function.
    1. Open an empty directory in VS Code. In the LOCAL RESOURCES list, click the plus icon to initialize a Function Compute project on premises.
      vscode_create_function
    2. Enter the service name, function name, function runtime environment, and function type in sequence as instructed. After you set these 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 plus icon next to a service in the LOCAL RESOURCES list to create a function for the service. Enter or select the function name, function runtime environment, and function type in sequence as instructed. 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 the deployment is complete, 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 functions on premises
    In the LOCAL RESOURCES list, click the Local Run icon next to a function or Local Run in the handler file to invoke the function on premises. vscode_local_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 directory where 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 functions on premises
    Important
    • If you need to debug functions that are run in Python 2.7 or Python 3, you must first install the Python extension.
    • If you need to debug functions that are run in PHP 7.2, you must first install the PHP Debug extension.
    In the LOCAL RESOURCES list, click the Debug icon next to a function or Local Debug in the handler file to debug the function on premises. vscode_local_debug
    Set breakpoints in code and start debugging. The debugging information is displayed. vscode_local_debug_result

    Aliyun Serverless VSCode Extension creates an event.dat file in the directory where 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 corresponding project. You can modify the event.dat file to configure events that are triggered when the function is invoked.

  • Set parameters in templates files

    Funcraft uses YAML template files to describe serverless applications. When you use Aliyun Serverless VSCode Extension to create a function, default values are automatically used for parameters in the corresponding template file. If you need to modify the configuration 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 corresponding description blocks are highlighted and then gradually dimmed.

    vscode_goto_template
  • Obtain template prompts
    • Automatic completion

      All keys in the template.yml file are automatically completed based on precise prompts 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.

    • 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 is displayed for the corresponding resource. This prompt shows configurable fields under this resource key, such as the field name and field type.

Feedback

If you encounter problems when you use Aliyun Serverless VSCode Extension, contact Function Compute engineers or give feedback on GitHub.