This topic describes how to troubleshoot issues that may occur when you use Function Compute as a back-end service of API Gateway.
Q1: Error code 503 is returned when functions are triggered in API Gateway but the function log shows that the function has been executed. How do I resolve this issue?
A1: API Gateway requires Function Compute to return responses in a specific format. If the returned result is not in the expected format, API Gateway considers the back-end service to be unavailable. For more information about the format requirements of API Gateway and Function Compute, see Format requirements of API Gateway and Function Compute.
Q2: How do I set the content type of the returned response?
A2: As shown in the figure, you can set the content type of a response when setting the API.
Q3: Error code 503 is returned when I call a function that has been previously called, but has not been called for some time. How do I resolve this issue?
A3: If a function is not called for a period of time, a new execution environment must be prepared when the function is called again, causing a cold start delay. This may cause the call not to be able to complete within the timeout period, and API Gateway considers the back-end service unavailable. To resolve this problem, extend the timeout period.
Q4: Why are the bodies of the requests passed from API Gateway to the function encoded in Base64?
A4: The bodies of the requests are encoded in Base64 to prevent content transmission errors or loss. Bodies in form format transmitted through API Gateway is not Base64-encoded. You must select Input Parameter Mapping in API Gateway when transmitting bodies in form format. We recommend that you check whether the value of the isBase64 field in the event is true before decoding events in the function. For more information about the formats of events that API Gateway passes to Function Compute, see the Test functions topic.