Symptoms
I create an HTTP function for a custom runtime. The service name is CustomDemo and the function name is func-http. An anonymous HTTP trigger is specified. The following sample routing code can be used to implement the HTTP server of the custom runtime:
@app.route('/test', methods = ['POST','GET'])
def test():When I use the cURL tool or a browser to access the URL of the HTTP function, a
404 error occurs. - Use the cURL tool to access the HTTP function.
curl -v https://123456789.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test - Use a browser to access the HTTP function.
https://123456789.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/testNote The URL format of the HTTP function is https://$ACCOUNT_ID.$REGION.fc.aliyuncs.com/2016-08-15/proxy/$ServiceName/$functionName/$path.
Solutions
You can use one of the following methods to solve this problem:
- Add a header named
x-fc-invocation-targetto the command. Command syntax:
A sample command:curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/$ServiceName/$functionName" https://$ACCOUNT_ID.$REGION.fc.aliyuncs.com/$pathcurl -v -H "x-fc-invocation-target: 2016-08-15/proxy/CustomDemo/func-http" https://123456789.cn-hangzhou.fc.aliyuncs.com/test - Bind a custom domain name to the function. Then, run the following command to access the function again. For more information about how to bind a domain name, see Configure a custom domain name. If the domain name is
test.abc.com, the following command can be used:
A sample command:curl -v https://test.abc.com/$pathcurl -v https://test.abc.com/testImportant The path must be/*. The service name is CustomDemo and the function name is func-http. - Modify your function code and deploy the function. Then, use the default URL to access the function again. An example of modified function code:
A sample command:@app.route('/2016-08-15/proxy/CustomDemo/func-http/test', methods = ['POST','GET']) def test():curl -v https://123456789.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test