All Products
Search
Document Center

Function Compute:Trigger a function with a GetObject request using an Object FC Access Point

Last Updated:Oct 01, 2025

You can create an Object FC Access Point in Object Storage Service (OSS) to integrate OSS with Function Compute (FC). When you use an Object FC Access Point, a GetObject request automatically triggers a function and returns the processed results to your application. This integration automates data processing and business workflows.

Process overview

The following figure illustrates how an Object FC Access Point works.

image
  1. The bucket owner creates an Object FC Access Point that is associated with a function created in Function Compute.

  2. The Object FC Access Point is automatically created based on the specified settings.

  3. The user sends a GetObject request to OSS by using the Object FC Access Point. OSS invokes the defined function to process and return requested data to the user.

Limits

Limit

Description

Creation methods

You can create an Object FC Access Point only by using the OSS console or OSS API. You cannot create an Object FC Access Point by using OSS SDKs or ossutil.

Number of Object FC Access Points

  • You can create up to 1,000 Object FC Access Points for an Alibaba Cloud account.

  • You can create up to 100 Object FC Access Points for a bucket.

Modification rule

After you create an Object FC Access Point, you can modify only its policy. You cannot modify the basic information about the Object FC Access Point, such as its name and alias.

Access methods

An Object FC Access Point does not support anonymous access.

Prerequisites

  • Object Storage Service (OSS)

    Create a bucket and create an access point in the region where the bucket is located.

  • Function Compute (FC)

    1. Create the service-linked role AliyunServiceRoleForFC. If you log on to the Function Compute 3.0 console for the first time, follow the instructions to create the role.

    2. Create an FC function. This topic uses an event function as an example. The FC function is triggered when you call the GetObject operation using the OSS SDK for Java, Python, or Go. When you deploy the function code using these SDKs, you must create a function that meets the corresponding runtime environment requirements.

      • When you deploy function code using the Java SDK, create a function whose Runtime is Java 11.

      • When you deploy function code using the Python SDK, create a function whose Runtime is Python 3.10.

      • When you deploy function code using the Go SDK, create a function whose Runtime is Go 1.

    3. Attach a RAM role to the FC function. The RAM role must be granted the oss:WriteGetObjectResponse permission. For more information, see Grant permissions to a RAM role. The following code shows the policy document:

      {
        "Statement": [
          {
            "Action": "oss:WriteGetObjectResponse",
            "Effect": "Allow",
            "Resource": "*"
          }
        ],
        "Version": "1"
      }

Procedure

Step 1: Create an Object FC Access Point

  1. Log on to the OSS console. In the navigation pane on the left, click Object FC Access Points.

  2. On the Object FC Access Points page, click Create Object FC Access Point. In the Create Object FC Access Point panel, set the following parameters and click OK.

    Configuration item

    Description

    Region

    Select the region where the access point to associate is located. This is also the region where the OSS bucket is located.

    Object FC Access Point Name

    Enter a name for the Object FC Access Point.

    Supporting Access Point

    Select the created access point.

    OSS API

    Select GetObject.

    Function to Invoke

    Select the target FC function and select the FC Function Supports Range GetObject Requests check box.

    FC Function Version

    Select the version of the created function. By default, the LATEST version is used.

  3. Complete the role authorization.

    Important

    If you are using the Object FC Access Point feature for the first time, click Access Point Permission Delegation to complete the role authorization. Otherwise, you cannot use Object FC Access Points to access functions.

    image

Important

The FC function is triggered only when you call the GetObject operation using the alias of an Object FC Access Point. If you use the alias of an Object FC Access Point to call an operation other than GetObject, the system automatically switches to the standard access point and follows the access policy of the standard access point.

Step 2: Write function code

  1. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  2. In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.

  3. Choose Function Details > Code. In the code editor, replace the code in the index.py file with the following sample code. This topic uses a function whose runtime is Python 3.10 as an example. For more information about sample code, see Write request functions.

    # -*- coding: utf-8 -*-
    import io
    from PIL import Image
    import oss2
    import json
    
    # In this example, the endpoint of the China (Qingdao) region is used.
    endpoint = 'http://oss-cn-qingdao.aliyuncs.com'
    fwd_status = '200'
    
    # Fc function entry
    def handler(event, context):
    
        evt = json.loads(event)
        creds = context.credentials
        # do not forget security_token
        auth = oss2.StsAuth(creds.access_key_id, creds.access_key_secret, creds.security_token)
    
        headers = dict()    
    
        event_ctx = evt["getObjectContext"]
        route = event_ctx["outputRoute"]
        token = event_ctx["outputToken"]
        print(evt)
    
        endpoint = route
        service = oss2.Service(auth, endpoint)
        # Call the Image method to create an object of 200 × 200 pixels and draw a red rectangle for the object.
        # After the adjustments, write the content to the body of the write_get_object_response request.
        image = Image.new('RGB', (200, 200), color=(255, 0, 0))
        transformed = io.BytesIO()
        image.save(transformed, "png")
    
        resp = service.write_get_object_response(route, token, fwd_status, transformed.getvalue(), headers)
    
        print('status: {0}'.format(resp.status))
        print(resp.headers)
    
        return 'success'
  4. On the Code tab, choose Terminal > New Terminal to open a terminal window. Run the following command to update the OSS Python SDK version.

    pip install oss2 "pyopenssl>=23.0.0" "urllib3==1.26.15" "charset-normalizer==2.1.1"  -t .
  5. Click Deploy Code.

Step 3: Use the Object FC Access Point

After you create an Object FC Access Point, OSS automatically generates an alias for it. You can use the alias to call the GetObject operation.

  1. Log on to the OSS console. In the navigation pane on the left, click Object FC Access Points.

  2. In the list of Object FC Access Points, obtain the Object FC Access Point Alias of the target access point.

    image

  3. Use one of the following methods to call the GetObject operation with the Object FC Access Point alias to test whether the function is automatically triggered.

    Use an SDK

    1. Install the OSS SDK for Python. Only OSS SDK for Python 2.18.3 and later supports accessing OSS resources using the alias of an Object FC Access Point.

      pip3 install oss
    2. Run the following Python sample script on your computer.

      Replace the endpoint, bucketname, and bucket.get_object_to_file parameters in the following sample code with your actual values.

      • endpoint: The endpoint of the OSS region.

      • bucketname: The alias of the target Object FC Access Point that you obtained in the previous step.

      • bucket.get_object_to_file: Replace yourObjectName with the name of an object in your OSS bucket and yourLocalFile with the local path where you want to save the file.

      # -*- coding: utf-8 -*-
      import oss2
      from oss2.credentials import EnvironmentVariableCredentialsProvider
      
      # Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
      auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider())
      # Use the public endpoint of the Object FC Access Point to access OSS resources.
      endpoint = "https://oss-cn-qingdao.aliyuncs.com"
      # Use the internal endpoint of the Object FC Access Point to access OSS resources.
      # endpoint = "https://oss-cn-qingdao-internal.aliyuncs.com"
      # Enter the alias of the Object FC Access Point.
      bucket_name = "****-d54843759613953fe5b17b6f16d7****-opapalias"
      bucket = oss2.Bucket(auth, endpoint=endpoint, bucket_name=bucket_name)
      
      # Set yourObjectName to the full path of the object. Do not include the bucket name in the full path.
      # Set yourLocalFile to the path of the local file. If the specified local file exists, it is overwritten. If it does not exist, it is created.
      bucket.get_object_to_file('yourObjectName', 'yourLocalFile')

    Use the ossutil command-line tool

    Install ossutil and run the following command to test.

    ossutil cp oss://****-d54843759613953fe5b17b6f16d7****-opapalias/demo.txt /Users/demo/Desktop/demo.txt

    Use a REST API

    When you send a GetObject request to access OSS resources, you must specify the alias of the Object FC Access Point that you obtained in the previous step in the Host header. The following code provides an example:

    GET /ObjectName HTTP/1.1
    Host: fc-ap-01-3b00521f653d2b3223680ec39dbbe2****-opapalias.oss-cn-qingdao.aliyuncs.com
    Date: GMT Date
    Authorization: SignatureValue