In this guide, you will go through the process of activating Log Service, creating a Log Service project and two Logstores, creating a Function Compute service, creating a Function Compute function, and then configure a Log Service trigger. Skip this guide if you have available Log Service, Functions, and Log Service Trigger.
Make sure that Function Compute and Log Service are deployed in the same region. Otherwise, Function Service cannot locate Log Service when you configure the Log Service trigger. For more information, see Regions and zones.
Log on to the Alibaba Cloud console.
Navigate to the
AliyunLogETLRolerole management page, click the Confirm Authorization Policy button to grant Function Compute the
Log on to Log Service console, create one Logstore to process log files and data sources, and create another Logstore to store the log files that are generated by Function Compute. For more information, see Log Service topic Preparation.
Log on to the Function Compute console and create a Service. In the Create Service dialog box that appears:
Select a region, in this sample, we use the China (shanghai) region.
Click Create Service.
In the Create Service dialog box that appears, enter the service name, in this sample, the service name is log-com.
Enable the Advanced Settings option.
In the Log Configs, set your available Log Project and Logstore.
In the Role Config, select Create new role from the Role Operation drop-down list, select
AliyunLogReadOnlyAccessfrom the System Policies drop-down list.
Click Authorize and OK to confirm your action.
In the left-side navigation pane, select the new service you created.
Click Create Function to go to the Create Function page.
- Click Select All, and select python2.7 from the drop-down list. This sample takes Python code execution for example.
Click Select in Empty Function.
Note: You can create the trigger during or after function creation. Then, you can configure the trigger. For more information, see Basic operations.
Select Log Service (Log) from the Trigger Type drop-down list, set the Trigger Name, Log Project Name, Trigger Log, Invocation Interval, Retry Count, and Function Configuration configuration. In this sample, we set the trigger as follows:
You can set the Function Configuration field according to the event parameter in your function code. In this sample, we set the Function Configuration as follows:
Configure the Service Name, Function Name, Function Description, Runtime, and Runtime Environment parameters.
- Click Next.
- Make sure that all the settings are correct, and then click Create.
For more information about creating services in the console, see Create a service.
Function logs are saved to the Logstore and used in debugging. For more information about logs, see Function logs.
Roles that you configure in Function Compute automatically have access permissions for other cloud services. For more information about permissions, see Introduction.