All Products
Search
Document Center

1. Set up services

Last Updated: Oct 16, 2018

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.

Preparations

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.

  1. Log on to the Alibaba Cloud console.

  2. Navigate to the AliyunLogETLRole role management page, click the Confirm Authorization Policy button to grant Function Compute the AliyunLogETLRole access policy.

  3. 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.

  4. Log on to the Function Compute console and create a Service. In the Create Service dialog box that appears:

    1. Select a region, in this sample, we use the China (shanghai) region.

    2. Click Create Service.

    3. In the Create Service dialog box that appears, enter the service name, in this sample, the service name is log-com.

    4. Enable the Advanced Settings option.

    5. In the Log Configs, set your available Log Project and Logstore.

    6. In the Role Config, select Create new role from the Role Operation drop-down list, select AliyunLogFullAccess and AliyunLogReadOnlyAccess from the System Policies drop-down list.

    7. Click Authorize and OK to confirm your action.

  5. In the left-side navigation pane, select the new service you created.

  6. Click Create Function to go to the Create Function page.

    1. Click Select All, and select python2.7 from the drop-down list. This sample takes Python code execution for example.
    2. 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.

    3. 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:
      Create a trigger

      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:

      1. {
      2. "source":{
      3. "endpoint": "http://cn-shanghai-intranet.log.aliyuncs.com"
      4. },
      5. "target": {
      6. "endpoint": "http://cn-shanghai-intranet.log.aliyuncs.com",
      7. "projectName": "etl-test",
      8. "logstoreName": "nginx_access_log_rep"
      9. }
      10. }
    4. Configure the Service Name, Function Name, Function Description, Runtime, and Runtime Environment parameters.

    5. Click Next.
    6. Make sure that all the settings are correct, and then click Create.

Next step

2. Author your function.

References

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