2017-01-03 30 views
1

我正在測試我的備份過程的API,在我的API Gateway中。API網關未導入導出的定義

因此,我從我的AWS賬戶中的API Console導出我的API,然後我進入API Gateway並創建一個新的API - 「從swagger導入」。

我粘貼導出的定義並創建,這會引發大量錯誤。

從我的閱讀 - 這似乎是一個已知的問題/痛苦。

我懷疑錯誤的原因是因爲我使用了自定義授權人;

"security" : [ { 
     "TestAuthorizer" : [ ] 
    }, { 
     "api_key" : [ ] 
    } ] 

我在每種方法上都使用這個,因此我得到了很多錯誤。

奇怪的是我可以很好地克隆這個API,因此,我認爲我可以採用導出的定義並重新導入而不會出現問題。

關於如何糾正這些錯誤的任何想法(最好在我的API網關中,以便我可以無任何問題導出/導入)。

使用這個授權我的GET方法中的一個例子是:提前

"/api/example" : { 
    "get" : { 
    "produces" : [ "application/json" ], 
    "parameters" : [ { 
     "name" : "Authorization", 
     "in" : "header", 
     "required" : true, 
     "type" : "string" 
    } ], 
    "responses" : { 
     "200" : { 
     "description" : "200 response", 
     "schema" : { 
      "$ref" : "#/definitions/exampleModel" 
     }, 
     "headers" : { 
      "Access-Control-Allow-Origin" : { 
      "type" : "string" 
      } 
     } 
     } 
    }, 
    "security" : [ { 
     "TestAuthorizer" : [ ] 
    }, { 
     "api_key" : [ ] 
    } ] 
    } 

感謝

UPDATE

錯誤(S)導入定義時,我得到的我剛剛輸出的是: Your API was not imported due to errors in the Swagger file. Unable to put method 'GET' on resource at path '/api/v1/MethodName': Invalid authorizer ID specified. Setting the authorization type to CUSTOM or COGNITO_USER_POOLS requires a valid authorizer.

我得到消息f或者我的API中的每個方法 - 所以有很多。

額外性,就在郵件的末尾,我得到這個: Additionally, these warnings were found: Unable to create authorizer from security definition: 'TestAuthorizer'. Extension x-amazon-apigateway-authorizer is required. Any methods with security: 'TestAuthorizer' will not be created. If this security definition is not a configured authorizer, remove the x-amazon-apigateway-authtype extension and it will be ignored.

我已經與忽略的錯誤,同樣的結果嘗試。

+0

您好,我有我自己的API,有一個自定義的授權測試,它導出/導入成功,所以我認爲這可能是別的。你能發佈你在導入時看到的確切的錯誤信息嗎?另外,你有沒有嘗試禁用導入時的「失敗警告」選項? –

+0

@LorenzodeLara感謝您的反饋,我已更新我的原始問題與所需的信息,讓我知道如果你需要別的東西。 – Hexie

回答

1

對於任何可能遇到此問題的人。

經過多次故障排除並最終涉及到AWS Support Team後,已解決此問題並將其識別爲AWS CLI客戶端錯誤(從AWS Support Team確認);

最終回覆。

謝謝您提供所需的詳細信息。在查看AWS CLI版本和錯誤詳細信息後,我可以確認錯誤是由於Powershell AWS CLI的已知問題。對由於錯誤造成的不便,我表示歉意。爲了解決我建議通過以下步驟會錯誤

  1. 創建一個名爲data.json在當前目錄下的文件,其中PowerShell命令被執行

  2. 保存下列內容到文件{ 「擴展」:「授權人,集成」}

  3. 在Powershell的控制檯中,確保當前工作目錄是一樣的,其中data.json存在於位置

  4. 執行以下命令aws apigateway get-export --parameters file://data.json --rest-api-id APIID --stage-name dev --export-type swagger C:\ temp \ export.json

使用這個,最終解決了我的問題 - 我期待在即將到來的版本之一的修復。

PS - 這是目前最新的版本:

aws --version

aws-cli/1.11.44 Python/2.7.9 Windows/8 botocore/1.5.7

0

確保您使用集成和授權人擴展功能導出您的swagger。

嘗試使用導出您AWS CLI招搖:

aws apigateway get-export \ 
    --parameters '{"extensions":"integrations,authorizers"}' \ 
    --rest-api-id {api_id} \ 
    --stage-name {stage_name} \ 
    --export-type swagger swagger.json 

輸出將被髮送到swagger.json文件。

有關swagger自定義擴展的更多詳細信息,請參閱this

+0

使用你的鏈接和例子,我能夠把大部分內容都弄清楚,絕對是指向正確的方向。現在我只需要一件事,就是爲我的CLI腳本添加多個擴展,這就是我得到的: 'aws apigateway get-export --parameters extensions ='authorizers'--rest-api-id APIID - stage-name dev --export-type swagger C:\ temp \ export.json',我假設我還需要添加集成擴展以及? – Hexie

+0

@Hexie是的,沒錯。如果您想通過導入swagger規範來重新創建API,則還需要集成擴展。 嘗試使用JSON表示法參數: 'aws apigateway get-export --parameters'{「extensions」:「integrations,authorizers」}'--rest-api-id APIID --stage-name dev --export-鍵入swagger C:\ temp \ export.json' – vnasc

+0

仍然沒有運氣,我試圖將參數更改爲JSON表示法,但然後得到這個:'解析參數錯誤 - 參數':預期:'=',收到:' ''輸入: '{extensions:authorizers,integrations}''其他建議? 該命令現在看起來像這樣:'aws apigateway get-export --parameters'{「extensions」:「authorizers,integrations」}'--rest-api-id APIID --stage-name dev --export-type swagger C:\ temp \ export.json' – Hexie