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.
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.
- Create a service.
- Create a function, write the code of the function, and then deploy the code to the function.
- Trigger the function.
- View the execution logs of the function.
- 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
- Directly trigger the execution of a function in the Function Compute console or by using Serverless Devs or SDKs. For more information, see the following topics:
- Configure a trigger in Function Compute and use events to trigger the execution of a function. For example, if you configure an Object Storage Service (OSS) trigger, the function is triggered when you create or delete an object in the corresponding OSS bucket. You can then process the uploaded object. If you configure a Log Service trigger, the function is triggered when new logs are written to the corresponding Logstore. You can then process the written logs. A trigger is required to specify how the function is triggered by an event. For more information, see the following topics:
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.