All Products
Search
Document Center

3. Test function

Last Updated: Oct 16, 2018

Before creating a trigger, you can simulate the execution process by triggering an event. In this step, it simulates the execution process of Function Compute when an object in the source/ directory is created in the OSS bucket. You can use this method for debugging and testing.

You can specify an OSS event source as the event parameter in the function and test whether the encoding is correct.

Procedures

To test the function in the Function Compute console, follow these steps:

  1. Log on to the Function Compute console.

  2. On the code execution page, click Trigger Event.

  3. Set the trigger event as OSS trigger event.

  4. Click Invoke.

  5. After the function is executed successfully, you can find the processed directory named under the corresponding OSS bucket. This directory contains the serverless.png processed image.

    Simulation

  6. In the Test Event dialog box, select OSS Template, and edit your arn, name, ownerIdentity, and key parameters in the event template accordingly.

    1. {
    2. "events": [
    3. {
    4. "eventName": "ObjectCreated:PutObject",
    5. "eventSource": "acs:oss",
    6. "eventTime": "2017-04-21T12:46:37.000Z",
    7. "eventVersion": "1.0",
    8. "oss": {
    9. "bucket": {
    10. "arn": "acs:oss:cn-shanghai:1237050315505689:bucketname",
    11. "name": "bucketname",
    12. "ownerIdentity": "1237050315505689",
    13. "virtualBucket": ""
    14. },
    15. "object": {
    16. "deltaSize": 122539,
    17. "eTag": "688A7BF4F233DC9C88A80BF985AB7329",
    18. "key": "image/a.jpg",
    19. "size": 122539
    20. },
    21. "ossSchemaVersion": "1.0",
    22. "ruleId": "9adac8e253828f4f7c0466d941fa3db81161e853"
    23. },
    24. "region": "cn-shanghai",
    25. "requestParameters": {
    26. "sourceIPAddress": "140.205.128.221"
    27. },
    28. "responseElements": {
    29. "requestId": "58F9FF2D3DF792092E12044C"
    30. },
    31. "userIdentity": {
    32. "principalId": "262561392693583141"
    33. }
    34. }
    35. ]
    36. }

Next step

Create an OSS trigger.

Reference

Configure triggers and events.