This topic describes how to use Function Compute, including how to create a service, create a function, trigger a function, view execution logs, and view service monitoring data.

Background information

You can create functions and view logs in the Function Compute console or by using Serverless Devs or Aliyun Serverless VSCode Extension. For more information, see the following topics:

Procedure

Before you can use Function Compute, you must activate the service on the product page.

The following figure shows the procedure for using Function Compute.

workflow
The preceding procedure consists of the following steps:
  1. Create a service.
  2. Create a function, write the code of the function, and then deploy the code to the function.
  3. Trigger the function.
  4. View the execution logs of the function.
  5. View service monitoring data.

Create a service

A service is the basic unit of resources in Function Compute. You can grant permissions, configure logging, and create functions for a service. For more information, see Manage microservices.

Create a function

A function is the basic unit for scheduling and running in Function Compute. It is essentially the processing logic of a code block. To create a function, you must write code by using relevant API operations provided by Function Compute and deploy the code to Function Compute as a function. A service in Function Compute resembles a microservice in the software application architecture. When you build an application in Function Compute, you must abstract the business logic into microservices based on your needs and implement the microservices as services in Function Compute.

You can create one or more functions for a service. For each function, you can set properties such as the memory size and environment variables. You can determine whether to enable the initializer feature based on your business scenarios. For more information about initializer functions, see Terms.

For example, you need to implement a microservice. You can use the speech synthesis service of Alibaba Cloud to convert text to speech and combine the speech with a series of images to generate a video. In this case, the function that is used to convert text to speech is called from another service. You can specify a small memory size for the function. However, the function that is used for video synthesis is computing-intensive and therefore requires a larger memory size. To reduce costs, you can combine functions of different specifications to implement a microservice. For more information about how to create, modify, and delete functions, see Function management.

Trigger a function

You can trigger a function directly or by using events in Function Compute. Select one of the following methods to suit your needs:

View execution logs

Viewing logs can help you debug a function. For more information about how to configure logging and view logs in Function Compute, see Configure logging.

View service monitoring data

You can view the monitoring data of a service in the Function Compute console. For more information, see the following topics: