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

时间:2016-12-29 01:19:11

标签: aws-lambda aws-api-gateway aws-cli serverless-architecture

使用AWS CLI

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

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

使用AWS CLI https://github.com/arun-gupta/serverless/tree/master/aws/microservice#get-method创建GET方法。使用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
}

错误消息中标识的ARN为arn:aws:execute-api:us-west-1:598307997273:sofl9ilki7/null/GET/books。想知道null而非test是否导致此失败?

4 个答案:

答案 0 :(得分:25)

我认为你正在使用&#34; GET&#34;对于GET方法的Lambda函数端点也是如此。请更改它以使用&#34; POST&#34;用于Lambda集成HTTP方法。

答案 1 :(得分:1)

要调用lambda函数,http方法应该按照lambda API 进行POST:

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

答案 2 :(得分:0)

源ARN中的null是因为test-invoke没有与API关联的阶段。这通常不是问题,除非您的Lambda函数上的策略期望不兼容的源ARN。检查Lambda函数的策略,看它是否包含对源ARN的限制。如果是,请将其编辑为与测试调用ARN兼容,或者将API部署到舞台并直接调用该方法而不进行测试调用。

答案 3 :(得分:0)

请注意API网关使用POST方法调用Lambda,同时允许任何方法通过x-amazon-apigateway-any-method调用它。