Symptoms

I create an HTTP function for a custom container 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 container 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/test
    Note 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-target to the command. Command syntax:
    curl -v "x-fc-invocation-target: 2016-08-15/proxy/$ServiceName/$functionName" https://$ACCOUNT_ID.$REGION.fc.aliyuncs.com/$path
    A sample command:
    curl -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 Bind a custom domain name.
    If the domain name is test.abc.com, the following command can be used:
    curl -v  https://test.abc.com/$path
    A sample command:
    curl -v  https://test.abc.com/test
    Notice 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:
    @app.route('/2016-08-15/proxy/CustomDemo/func-http/test', methods = ['POST','GET'])
    def test():
    A sample command:
    curl  -v  https://123456789.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test