All Products
Search
Document Center

3. Test functions

Last Updated: Aug 07, 2018

When API Gateway triggers the execution of a function in Function Compute, data from API Gateway is passed to the event input parameter of the function. You can use this parameter for function debugging.

Limits

When you must debug the function code, consider the following:

  • The format of parameters that are used in the data communication between API Gateway and Function Compute must meet certain requirements.

  • Before you test a function, you can modify the format of the trigger event in the console.

Request format for API Gateway

When Function Compute serves as a backend service of API Gateway, API Gateway passes the request parameters to the event input parameter of Function Compute in a pre-defined structure. Function Compute obtains the parameters as follows, and then processes the obtained parameters:

  1. {
  2. "path":"api request path",
  3. "httpMethod":"request method name",
  4. "headers":{},
  5. "queryParameters":{},
  6. "pathParameters":{},
  7. "body":"string of request payload",
  8. "isBase64Encoded":true|false
  9. }

Response format of Function Compute

Function Compute must return the output to API Gateway in the following JSON format. Output in this format can be parsed by API Gateway more easily.

  1. {
  2. "isBase64Encoded":true|false,
  3. "statusCode":httpStatusCode,
  4. "headers":{response headers},
  5. "body":"..."
  6. }

Test function

To test a function, go to the code editing page of the console and follow these steps:

  1. Click Code Management, click Event, and then write the format of the input parameter from API Gateway into the trigger event.

  2. Click OK to save the test event.

  3. Click Invoke to trigger function execution.