If you want to use an event source such as Object Storage Service (OSS) to trigger function execution, you can grant the event source the permissions to trigger the execution. You can grant the permissions to the role of each trigger, and assign this role to different triggers. This topic describes the scenarios and procedure on how to grant permissions to an event source to access Function Compute. In this topic, the OSS event source is used as an example to access Function Compute.

Scenario

In this example, an OSS event source is used to trigger code execution in Function Compute. If you want to trigger function B in Function Compute after you upload files to OSS bucket A, you must create an OSS event trigger and then attach the required policy to the trigger. Resource Access Management (RAM) provides the AliyunOSSEventNotificationRole policy. You can use this policy to grant an OSS event trigger the permissions to trigger code execution in Function Compute. When you create an OSS event trigger, you can assign a new RAM role or an existing RAM role to the trigger, and attach the AliyunOSSEventNotificationRole policy to the RAM role. Then, you can use the OSS event trigger to trigger code execution in Function Compute. buhuoshijianyuanfangshujisuan

Procedure

  1. Log on to the Function Compute console.
  2. In the left-side navigation pane, click Services and Functions.
  3. In the top navigation bar, select the region where your Kubernetes cluster is deployed.
  4. On the Services page, find the service that you want to manage and click Functions in the Actions column.
  5. On the Functions page, click the name of the function that you want to manage.
  6. On the function details page, click the Triggers tab, select the version or alias from the Version or Alias drop-down list, and then click Create Trigger.
    Create a webhook
  7. In the Create Trigger panel, enter the relevant information. Click OK.
    Note If you want to grant permissions to other types of triggers, perform the steps as described in this section. You only need to select a trigger type based on your business requirements. The event source of an HTTP trigger is created when you create an HTTP function.
    Parameter Description Example
    Trigger Type The type of the trigger. Select OSS. OSS
    Name The name of the trigger. Enter a custom trigger name. oss-trigger
    Version or Alias The version or alias of the service. The default value is LATEST. If you want to create a trigger for another version or alias, select a version or alias from the Version or Alias drop-down list on the function details page. For more information about versions and aliases of a service, see Manage versions and Manage aliases. LATEST
    Bucket Name The name of the OSS bucket. Select an OSS bucket from the drop-down list. bucket-zh****
    Object Prefix The prefix of the object that you want to match. We recommend that you configure prefixes and suffixes to avoid additional costs generated by function execution loops. If you specify the same event type for different triggers of a bucket, the prefixes or suffixes cannot be repeated. For more information, see Trigger rules. source
    Object Suffix The suffix of the object name you want to match. We recommend that you configure prefixes and suffixes to avoid additional costs generated by function execution loops. If you specify the same event type for different triggers of a bucket, the prefixes or suffixes cannot be repeated. For more information, see Trigger rules. zip

    Trigger Event

    The trigger event. Select one or more trigger events from the drop-down list. For more information about OSS events, see Definition of OSS events.

    In this example, oss:ObjectCreated:PutObject is selected.

    oss:ObjectCreated:PutObject
    Role Name The name of the role. Select AliyunOSSEventNotificationRole.
    Note After you set the preceding parameters, click OK. If you create a trigger of this type for the first time, click Authorize Now in the dialog box that appears.
    AliyunOSSEventNotificationRole
  8. Click OK.