4

我已經使用了Swagger Editor來創建一個REST API,並且我已經請求了Python Flask的服務器代碼下載。我試圖將其部署到Google Cloud Platform(我認爲這是最新的名稱?或者它仍然是GAE?),但我需要填補一些空白。Python燒瓶:從Swagger YAML轉到Google App Engine?

我知道Swagger代碼的工作原理,因爲我在本地部署了它,沒有任何問題。但是,它使用connexion庫而不是Flask徹底。

我大部分都不知道如何爲GCP和生成的代碼中的正確入口點合併app.yaml文件。另外,我知道生成的代碼聲明瞭它自己的應用服務器,我認爲您不需要爲GCP做。 這是我目前的的app.yaml

application: some-app-name 
version: 1 
runtime: python27 
api_version: 1 
threadsafe: yes 
entrypoint: python app.py 

libraries: 
- name: connexion 
    version: "latest" 

這是我的app.py

import connexion 

if __name__ == '__main__': 
    app = connexion.App(__name__, specification_dir='./swagger/') 
    app.add_api('swagger.yaml', arguments={'title': 'this is my API'}) 
    app.run(port=8080) 

現在我得到的主要錯誤是

google.appengine.api.yaml_errors.EventError: the library "connexion" is not supported 

我有一個感覺這是因爲我在我的app.py中聲明瞭一個應用程序服務器 - 可能不需要它。我如何修改這個文件來繼續使用我的Swagger代碼,但在GCP上運行?

+1

堅持GAE,GCP包括GAE,但也包括其他Google產品,有些與GAE完全無關:https://cloud.google.com/products/ –

回答

4

您的文件似乎存在一些不一致之處,但您是否打算將其設置爲standard environment app.yaml fileflexible environment之一,這一點尚不清楚。我不能說,因爲我不熟悉招搖和燒瓶。

如果它應該是一個標準的環境之一,那麼:

可能是一個好主意,要經過Getting Started with Flask on App Engine Standard Environment

但是,如果你的目標是一個靈活的環境app.yaml文件,然後: