-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
main.py
from fastapi import FastAPI
from mangum import Mangum
app = FastAPI()
handler = Mangum(app)
@app.get("/")
async def hello():
return {"message": "Hello World"}打包
相關文獻:連結
建立 package 資料夾,輸入以下指令輸出套件環境,最後修改為你的套件庫,以及修改你的Python版本
踩到的坑:網路上教學是 pip install -t dep -r ./requirements.txt,但是實際部屬後會遇到 Q1 的問題,透過官方給的指令後才正常運行
pip install --platform manylinux2014_x86_64 --target=package --implementation cp --python-version 3.10 --only-binary=:all: --upgrade -r requirements.txt將你的Python環境丟到 package 資料夾根目錄
最後zip裡面會像這樣

遇到過的問題
Q1:啟動後出現
[ERROR] Runtime.ImportModuleError: Unable to import module 'main': No module named 'pydantic_core._pydantic_core'
A1:
https://github.com/pydantic/pydantic/issues/6557
https://docs.aws.amazon.com/zh_tw/lambda/latest/dg/python-package.html
Reactions are currently unavailable