All Products
Search
Document Center

Function Compute:What do I do if a 404 error occurs when I use a browser or the cURL tool to access a function?

Last Updated:Feb 20, 2024

Problem description

I created an HTTP function of a custom runtime. The name of the service in which the function resides is CustomDemo, the name of the function is func-http, and an anonymous HTTP trigger is configured. The following sample code shows the routing of the HTTP function in 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, the error code 404 is returned.

  • Use the cURL tool to access the HTTP function

    curl  -v  https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test
  • Use a browser to access the HTTP function

    https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test
    Note

    The URL of the HTTP function is in the following format: https://<account_id>.<region_id>.fc.aliyuncs.com/<version>/proxy/<serviceName>/<functionName>/<path>.

Solution

You can use one of the following methods to resolve the issue:

  • Use Function Compute to access the function URL by using the subdomain that is allocated by the HTTP trigger. For more information, see the "Step 3: Test the function" section of the Configure and use an HTTP trigger topic.

    Subdomain format:

    https://<subdomain>.<region_id>.fcapp.run/[action?queries] 

    Sample code:

    https://funcname-svcname-khljsjksld.cn-shanghai.fcapp.run/action?hello=world
  • Add a header named x-fc-invocation-target to the command. Command syntax:

    curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/$ServiceName/$functionName" https://<account_id>.<region_id>.fc.aliyuncs.com/$path

    Sample code:

    curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/CustomDemo/func-http" https://164901546557****.cn-hangzhou.fc.aliyuncs.com/test
  • Bind a custom domain name to the function. Then, run the following command to access the function. For more information about how to bind a domain name, see Configure a custom domain name.

    For example, if the domain name is example.com, the following command syntax is used:

    curl -v  https://example.com/$path

    Sample code:

    curl -v  https://example.com/test
    Important

    Replace /$path with the path that is bound to the custom domain name of the function in the service. For more information, see the "Routing rules" section of the Configure a custom domain name topic.

  • Modify your function code and deploy the function. Then, use the default URL to access the function. The following example shows the modified code:

    @app.route('/2016-08-15/proxy/CustomDemo/func-http/test', methods = ['POST','GET'])
    def test():

    Sample code:

    curl  -v  https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test