Symptoms
I created an HTTP function that is named
func-http in the
CustomDemo service. The function runs in a custom runtime and an anonymous HTTP trigger is specified. The following sample routing code is 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, 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>
.
Solutions
You can resolve this issue by using one of the following methods:
- Access the function by using the subdomain that is assigned by Function Compute for the new HTTP trigger. For more information, see Step 3: Test the function.
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 that is named
x-fc-invocation-target
to the command that is used to access the function. Command syntax:
Sample code:curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/$ServiceName/$functionName" https://<account_id>.<region_id>.fc.aliyuncs.com/$path
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 again. 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:
Sample code:curl -v https://example.com/$path
curl -v https://example.com/test
Important Replace/$path
with the path from which a request can trigger the function in the service. The path is configured when you bind the custom domain. For more information, see Routing rules. - Modify your function code and deploy the function. Then, use the default URL to access the function. The following example shows the modified code:
Sample code:@app.route('/2016-08-15/proxy/CustomDemo/func-http/test', methods = ['POST','GET']) def test():
curl -v https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test