#OSS

Your Alibaba Cloud Function can be triggered by different event sources. Those event sources can be defined and configured with the help of the event event.

#OSS events

This example sets up a oss event which will trigger the first function whenever an object is uploaded to the my-service-resource under the account specified by the ALIYUN_ACCOUNT environment variable.

# serverless.yml

functions:
  first:
    handler: index.first
    events:
      - oss:
          sourceArn: acs:oss:cn-shanghai:${env:ALIYUN_ACCOUNT}:my-service-resource
          triggerConfig:
            events:
              - oss:ObjectCreated:PutObject
// index.js

exports.first = (event, context, callback) => {
  const response = {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Hello!',
    }),
  };

  callback(null, response);
};

Note: See the documentation about the function handlers to learn how your handler signature should look like to work this type of event.

Have questions?

Head over to the forums to search for your questions and issues or post a new one.