我想通過單個 lambda 函數調用代理來自根目錄的所有 HTTP 請求。我嘗試/{proxy+}在我的 serverless.yml 中設置為路徑。但是當我部署它時,我在訪問根目錄時收到“此頁面未正確重定向”。serverless.yml 片段functions: hello: handler: bin/hello url: true events: - httpApi:# path: /{proxy+} path: /{any+} method: get主程序import ( "fmt" "github.com/apex/gateway" "github.com/gin-gonic/gin" "log" "net/http" "os")func inLambda() bool { if lambdaTaskRoot := os.Getenv("LAMBDA_TASK_ROOT"); lambdaTaskRoot != "" { return true } return false}func setupRouter() *gin.Engine { gin.SetMode(gin.DebugMode) r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "home page"}) }) r.GET("/hello-world", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"message": "hello test completed successfully"}) }) return r}func main() { if inLambda() { fmt.Println("running aws lambda in aws") log.Fatal(gateway.ListenAndServe(":8080", setupRouter())) } else { fmt.Println("running aws lambda in local") log.Fatal(http.ListenAndServe(":8080", setupRouter())) }}
1 回答

呼喚遠方
TA貢獻1856條經驗 獲得超11個贊
path: /{proxy+}
是正確的。
確保您使用的是正確的 apex 版本。apex README聲明您需要將 apex v2 用于 HTTP API。您似乎正在使用僅支持 REST API 的 v1。
- 1 回答
- 0 關注
- 126 瀏覽
添加回答
舉報
0/150
提交
取消