Api Gateway can't invoke Lambda function

99封情书 提交于 2019-12-09 20:47:27

问题


Following this tutorial on AWS, I hit a roadblock when trying to test the api through the web console (as many others did):

Thu Nov 10 22:54:48 UTC 2016 : Execution failed due to configuration error: Invalid permissions on Lambda function

I've read every relevant post on SO and AWS forums I could find, but can't figure out how to grant permission to the API Gateway to invoke the Lambda function.


回答1:


Web Console Method:

Thanks to this mate I found a quick fix:

Go into the web console and select

The resource method > Integration Request > Pencil next to Lambda Function > Check mark next to lambda function (don't change the name)

A popup window should warn that you are granting permissions to the API to execute the lambda function.


API Method:

Also, thanks to Richard Downer for this code explanation:

A resource policy is different from an IAM Policy, setting the IAM policy will not work.

You need to use the Add-LMPermission api call after creation of Write-AGIntegration.

Here is an example:

Add-LMPermission -FunctionName myfunction -Action lambda:InvokeFunction -Principal apigateway.amazonaws.com -SourceArn arn:aws:execute-api:us-west-2:IAMAccountNumber:*/*/POST/apiendpoint -StatementId description



来源:https://stackoverflow.com/questions/40538493/api-gateway-cant-invoke-lambda-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!