1

使用AWS CLIAccessDeniedException異常:無法確定業務/運營的名字被授權

aws --version 
aws-cli/1.11.21 Python/2.7.12 Darwin/15.3.0 botocore/1.4.78 

創建API網關POST方法作爲https://github.com/arun-gupta/serverless/tree/master/aws/microservice#post-method解釋。可以使用test-invoke-method和AWS Console成功調用此方法。

使用AWS CLI創建GET方法https://github.com/arun-gupta/serverless/tree/master/aws/microservice#get-method。調用使用test-invoke-method這種方法和AWS控制檯提供了以下錯誤:

{ 
    "status": 500, 
    "body": "{\"message\": \"Internal server error\"}", 
    "log": "Execution log for request test-request\nThu Dec 29 00:58:56 UTC 2016 : Starting execution for request: test-invoke-request\nThu Dec 29 00:58:56 UTC 2016 : HTTP Method: GET, Resource Path: /books\nThu Dec 29 00:58:56 UTC 2016 : Method request path: {}\nThu Dec 29 00:58:56 UTC 2016 : Method request query string: {}\nThu Dec 29 00:58:56 UTC 2016 : Method request headers: {}\nThu Dec 29 00:58:56 UTC 2016 : Method request body before transformations: \nThu Dec 29 00:58:56 UTC 2016 : Endpoint request URI: https://lambda.us-west-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-west-1:598307997273:function:MicroserviceGetAll/invocations\nThu Dec 29 00:58:56 UTC 2016 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=******************************************************************************************************************************************************************************************************************************************************************************************************482377, X-Amz-Date=20161229T005856Z, x-amzn-apigateway-api-id=sofl9ilki7, X-Amz-Source-Arn=arn:aws:execute-api:us-west-1:598307997273:sofl9ilki7/null/GET/books, Accept=application/json, User-Agent=AmazonAPIGateway_sofl9ilki7, Host=lambda.us-west-1.amazonaws.com, X-Amzn-Trace-Id=Root=1-58645fd0-7d733ae3c383f4378fcc0338}\nThu Dec 29 00:58:56 UTC 2016 : Endpoint request body after transformations: \nThu Dec 29 00:58:56 UTC 2016 : Endpoint response body before transformations: <AccessDeniedException>\n <Message>Unable to determine service/operation name to be authorized</Message>\n</AccessDeniedException>\n\nThu Dec 29 00:58:56 UTC 2016 : Endpoint response headers: {x-amzn-RequestId=f95a8659-cd61-11e6-80f6-ddd6ce5b7e8b, Connection=keep-alive, Content-Length=130, Date=Thu, 29 Dec 2016 00:58:56 GMT}\nThu Dec 29 00:58:56 UTC 2016 : Lambda invocation failed with status: 403\nThu Dec 29 00:58:56 UTC 2016 : Execution failed due to configuration error: \nThu Dec 29 00:58:56 UTC 2016 : Method completed with status: 500\n", 
    "latency": 39 
} 

在錯誤消息中標識的ARN是arn:aws:execute-api:us-west-1:598307997273:sofl9ilki7/null/GET/books。想知道如果null而不是test是造成這種失敗?

回答

8

我認爲您在GET方法中也使用「GET」作爲您的Lambda函數端點。請將其更改爲使用「POST」作爲Lambda集成HTTP方法。

+0

這樣做的竅門,非常感謝!爲什麼GET'HTTP需要'POST'集成方法? –

+0

集成是您想要代理的API,方法是您要向客戶公開的API。由於Lambda使用POST方法定義了它們的調用API,所以您必須遵循他們定義API的任何內容。 –

+0

我很困惑。 AWS文檔給出了通過GET調用lambda表達式的示例:http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-lambda.html以及AWS上的註釋論壇,它可以讓它通過控制檯單獨工作:https://forums.aws.amazon.com/thread.jspa?threadID=209420。 – jazzbassrob

0

源ARN中的null是因爲test-invoke沒有階段與您的API相關聯。這通常不是問題,除非您的Lambda函數的策略期望不兼容的源ARN。檢查您的Lambda函數的策略,看它是否包含對源ARN的限制。如果有,請將其編輯爲與測試調用的ARN兼容,或者將API部署到一個階段,並直接調用該方法而不用測試調用。

-1

請注意API網關使用POST方法調用Lambda,同時允許任何方法通過x-amazon-apigateway-any-method調用它。