custom示例代码:
51ab7acc-929c-40fb-8247-d50a3a60304f.zip
项目目录
-rwxrwxrwx@ 1 apple staff 123B 4 21 18:40 Funfile # 必须,依赖包-rwxrwxrwx@ 1 apple staff 27B 4 21 14:59 bootstrap # 必须,启动脚本-rw------- 1 apple staff 231B 4 21 18:34 index.py # 主函数-rwxrwxrwx 1 apple staff 1.1K 4 21 18:25 template.packaged.yml-rw------- 1 apple staff 863B 4 21 18:34 template.yml # fc配置
发布
fun installfun package -b tianyunperfectfun deploy
Funfile
RUNTIME customRUN PYTHONUSERBASE=/code/.fun/python # 这一行不一定需要,我的mac是必须要加的RUN fun-install pip install fastapiRUN fun-install pip install uvicorn
bootstrap
#!/bin/bashpython index.py
index.py
from fastapi import FastAPIapp = FastAPI()@app.get('/random/') # 点get就支持get请求def read_root():return {"hello":'world'}if __name__ == '__main__':import uvicornuvicorn.run(app,host='0.0.0.0',port=9000)
template.yml
ROSTemplateFormatVersion: '2015-09-01'Transform: 'Aliyun::Serverless-2018-04-03'Resources:FastAPI-example: # service nameType: 'Aliyun::Serverless::Service'Properties:Description: This is FC serviceFastAPI-example: # function nameType: 'Aliyun::Serverless::Function'Properties:Handler: index.handlerRuntime: customCodeUri: ./MemorySize: 128Timeout: 120Events:httpTrigger:Type: HTTPProperties:AuthType: ANONYMOUSMethods: ['GET', 'POST', 'PUT']
