问题描述
跟随在AWS上的本教程,尝试通过Web控制台测试api时遇到了障碍(
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
我已经阅读了SO和AWS论坛上的所有相关文章,但无法弄清楚如何向API网关授予权限以调用Lambda函数.
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.
推荐答案
Web控制台方法:
感谢这位伴侣我找到了一个快速解决方法:
Web Console Method:
Thanks to this mate I found a quick fix:
进入网络控制台,然后选择
Go into the web console and select
资源方法>整合请求> Lambda函数旁边的铅笔> Lambda函数旁边的复选标记(请勿更改名称)
The resource method > Integration Request > Pencil next to Lambda Function > Check mark next to lambda function (don't change the name)
弹出窗口应警告您已授予API执行lambda函数的权限.
A popup window should warn that you are granting permissions to the API to execute the lambda function.
此外,还要感谢Richard Downer的这段代码说明:
Also, thanks to Richard Downer for this code explanation:
资源策略不同于IAM策略,因此无法设置IAM策略.
A resource policy is different from an IAM Policy, setting the IAM policy will not work.
创建Write-AGIntegration后,您需要使用Add-LMPermission api调用.
You need to use the Add-LMPermission api call after creation of Write-AGIntegration.
这里是一个例子:
Add-LMPermission -FunctionName myfunction -Action lambda:InvokeFunction -Principal apigateway.amazonaws.com -SourceArn arn:aws:execute-api:us-west-2:IAMAccountNumber:*/*/POST/apiendpoint -StatementId description
这篇关于Api Gateway无法调用Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!