AccessDeniedException:无法确定要授权的服务/操作名称

Aru*_*pta 6 aws-cli aws-lambda aws-api-gateway serverless-architecture

使用AWS CLI

aws --version
aws-cli/1.11.21 Python/2.7.12 Darwin/15.3.0 botocore/1.4.78
Run Code Online (Sandbox Code Playgroud)

按照https://github.com/arun-gupta/serverless/tree/master/aws/microservice#post-method中的说明为API网关创建POST方法.可以使用test-invoke-methodAWS Console 成功调用此方法.

使用AWS CLI创建GET方法https://github.com/arun-gupta/serverless/tree/master/aws/microservice#get-method.使用test-invoke-method和AWS Console 调用此方法会出现以下错误:

{
    "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
}
Run Code Online (Sandbox Code Playgroud)

错误消息中标识的ARN是arn:aws:execute-api:us-west-1:598307997273:sofl9ilki7/null/GET/books.想知道如果null代替test导致此失败?

Ka *_*ong 28

我认为您在GET方法上也使用"GET"作为Lambda函数端点.请将其更改为使用"POST"进行Lambda集成HTTP方法.

  • 成功了,非常感谢!为什么`GET` HTTP 需要`POST` 集成方法? (2认同)
  • 集成是您要代理的 API,而方法是您要向客户公开的 API。由于 Lambda 使用 POST 方法定义了它们的调用 API,因此您必须遵循它们定义的 API。 (2认同)
  • 我很困惑.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. (2认同)

kis*_*HoR 7

要调用 lambda 函数,http 方法应根据 lambda API为 POST :

访问 http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html