2017-10-04 48 views
0

我想使用aws cli設置一些自定義的API網關響應。這是我使用的命令(僅相關的參數):當設置了--response-parameters選項時,put-gateway-response失敗

aws apigateway put-gateway-response --response-parameters method.response.header.Access-Control-Allow-Origin='"'"'*'"'"' 

完整的命令是:

AWS apigateway放網關響應--rest -api-id w1s3nc4dxd --response-type UNAUTHORIZED --status-code 401 --response-parameters method.response.header.Access-Control-Allow-Origin =''''''''''''--response -templates'{「application/json」:「{\」errorcode \「:401,\」message \「:$ context.error.messageString}」}'--region eu-west-1

它失敗了個:

發生錯誤(BadRequestException)調用PutGatewayResponse操作時:無效的映射表達式指定:驗證結果:警告:[],錯誤:[無效的映射表達式指定:method.response.header.Access-控制-Allow-Origin]

如果在沒有該參數的情況下執行,則一切正常。我也嘗試過json格式和相同的結果。

--response-parameters '{"method.response.header.Access-Control-Allow-Origin":"'"'*'"'"}' 

任何見解?提前致謝。

---編輯

只是一個額外的澄清。這會失敗,並帶有所有類型的響應參數,這不僅涉及訪問控制 - 允許源頭。

+0

並啓用CORS? –

+0

嗯,我不確定爲什麼CORS與此相關。我的一些終點有一些啓用了CORS,而另一些則沒有。試圖設置一個頭到API網關響應。爲了使它更清楚,無論響應參數是什麼,它都會失敗。 – RoberMP

回答

0

我相信網關響應參數的格式應該是gatewayresponse.header.[name]。這將是在地圖鍵(目標),和值(源)是一個靜態值(如你有)或映射表達式method.request.(path|querystring|header).[name]stageVariables.[name]context.[name]