通过函数计算的Custom Runtime+HTTP Trigger的方式,您可以将Python的Web项目一键迁移至云上,并可直接使用浏览器或者Curl等HTTP客户端工具访问函数。
前提条件
- 安装8.6.0或以上版本的Node.js。更多信息,请参见官方下载地址。
- 安装Funcraft。更多信息,请参见安装Funcraft工具。
- 安装Docker。更多信息,请参见Dockerhub。
通过函数计算的Custom Runtime+HTTP Trigger的方式,您可以将Python的Web项目一键迁移至云上,并可直接使用浏览器或者Curl等HTTP客户端工具访问函数。
git clone https://github.com/awesome-fc/fc-custom-demo
cd fc-custom-demo
cd python37-http-demo
fun install -v
返回结果如下。using template: template.yml
start installing function dependencies without docker
building python37-demo/fc-python37-http
Funfile exist, Fun will use container to build forcely
Step 1/3 : FROM registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-custom:build-1.9.6
---> a9bade1e4f9c
Step 2/3 : RUN fun-install pip -i https://pypi.tuna.tsinghua.edu.cn/simple install flask
---> Using cache
---> c15874870502
Step 3/3 : RUN fun-install pip -i https://pypi.tuna.tsinghua.edu.cn/simple install gunicorn
---> Using cache
---> dc1f3f69d494
sha256:dc1f3f69d494e914e7a6c73b64eec5d4744baca6d976a203a179d3ef2dd9691c
Successfully built dc1f3f69d494
Successfully tagged fun-cache-08b1a909-bc37-4a1c-bb4a-4cca273f759f:latest
copying function artifact to C:\Users\demo\fc-custom-demo\python37-http-demo
Install Success
fun deploy -y
返回结果如下。Waiting for service python37-demo to be deployed...
Waiting for function fc-python37-http to be deployed...
Waiting for packaging function fc-python37-http code...
The function fc-python37-http has been packaged. A total of 368 files were compressed and the final size was 1.49 MB
Waiting for HTTP trigger http_t to be deployed...
triggerName: http_t
methods: [ 'GET', 'POST' ]
trigger http_t deploy success
function fc-python37-http deploy success
service python37-demo deploy success
Detect 'DomainName:Auto' of custom domain 'my_domain'
Fun will reuse the temporary domain http://********-*********.test.functioncompute.com, expired at 2020-12-20 15:18:04, limited by 1000 per day.
Waiting for custom domain my_domain to be deployed...
custom domain my_domain deploy success
curl -v http://********-*********.test.functioncompute.com
http://********-*********.test.functioncompute.com
可以从步骤5的返回结果中获取。
* Connected to ********-****************.test.functioncompute.com (47.111.48.14) port 80 (#0)
> GET / HTTP/1.1
> Host: ********-****************.test.functioncompute.com
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Access-Control-Expose-Headers: Date,x-fc-request-id,x-fc-error-type,x-fc-code-checksum,x-fc-invocation-duration,x-fc-max-memory-usage,x-fc-log-result,x-fc-invocation-code-version
< Content-Length: 12
< Content-Type: text/html; charset=utf-8
< X-Fc-Code-Checksum: 6465955828983873790
< X-Fc-Invocation-Duration: 3
< X-Fc-Invocation-Service-Version: LATEST
< X-Fc-Max-Memory-Usage: 85.20
< X-Fc-Request-Id: 1a26ecd3-3a6b-4b1c-9c33-e2eb0d71c7ec
< Date: Thu, 10 Dec 2020 07:23:21 GMT
<
* Connection #0 to host ********-****************.test.functioncompute.com left intact
Hello World!* Closing connection 0
在文档使用中是否遇到以下问题
更多建议
匿名提交