我创建了一个Custom Container Runtime的HTTP函数,其中服务名为 CustomDemo 、函数名为 func-http ,并且设置了匿名的HTTP触发器,实现Custom Container Runtime的HTTP Server的路由代码示例如下:

@app.route('/test', methods = ['POST','GET'])
def test():
当我使用cURL工具或浏览器等方式访问HTTP函数的URL时,遇到 404 报错。
  • 使用cURL工具访问HTTP函数。
    curl  -v  https://123456789.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test
  • 使用浏览器访问HTTP函数。
    https://123456789.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/test
    说明 HTTP函数的URL格式为: https://$ACCOUNT_ID.$REGION.fc.aliyuncs.com/2016-08-15/proxy/$ServiceName/$functionName/$path
    您可以选择以下任意方式解决该问题:
    • 在访问的命令中增加名为 x-fc-invocation-target 的Header。访问格式如下:
      curl -v "x-fc-invocation-target: 2016-08-15/proxy/$ServiceName/$functionName" https://$ACCOUNT_ID.$REGION.fc.aliyuncs.com/$path
      本文的访问示例如下:
      curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/CustomDemo/func-http" https://123456789.cn-hangzhou.fc.aliyuncs.com/test
    • 为您的函数绑定自定义域名,绑定成功后再执行以下命令重新访问即可。关于绑定域名的操作步骤,请参见 绑定自定义域名
      假设域名是 test.abc.com ,访问格式如下:
      curl -v  https://test.abc.com/$path
      本文的访问示例如下:
      curl -v  https://test.abc.com/test
      注意 您需要将路径设置为 /* ,本文对应的服务名为 CustomDemo 、函数名为 func-http
    • 修改您的函数代码,并且成功部署函数后,重新使用默认的URL访问即可。函数代码修改示例如下:
      @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
  •