You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it seems to me that there is a bug with the created LAMBDA-Policy when creating a "ANY"- API-Gateway-Mapping to a Lambda-Function, see the template here:
The created Lambda policy includes (for Resource analytics the following condition), and therefore a Lambda permission Error occurs when testing the API-Gateway:
...yes, the error occurs, when I test the function, Error-Message:
"Tue Jan 31 14:52:20 UTC 2017 : Execution failed due to configuration error: Invalid permissions on Lambda function
Tue Jan 31 14:52:20 UTC 2017 : Method completed with status: 500"
Hi @sanathkr , I'm experiencing the same problems as the others here. Hopefully I can provide some more info.
I have a SAM with an API and 3 lambdas. Everything is deployed successfully and connected using stage variables as well. My API cannot talk to the lambda because of the permissions issue mentioned above.
I was able to click to change the lambda:
and then this is the modal that popped:
After I said "OK", the lambda was reachable via API Gateway.
In addition, since I'm using a stage variable, it provided an extra message:
You defined your Lambda function as a stage variable; you must manually give permissions to all the functions you will use. You can do this by running the below AWS CLI command for each function, replacing the stage variable in the function-name parameter with the necessary function name.
Is there a step missing when the AWS::Serverless::Api is created to access the lambdas?
Reacted by Anatolii Klots, Eelke van den Bos, Graham Daw, qqRedDiamond, Brian Curtich, Gabriel Araújo, Michael Kilian, Efosa Oyegun, Evan Kozliner, Stephen Coe and 12 more
Reacted by Jason Haines, Evan Kozliner, liamvwood-iti and AlexanderBinkovsky
Reacted by Yosuke Torii, Jens Eickmeyer, Max Putilin, Ryan Anderson, Matthias Lübken, Jaume de Juan Sancho, Paulo Fernandes, Doug Ross, Philip M. Kennedy, JanneLindberg and 23 more
Reacted by mayur741, Yurii Hizun and Philippe Côté-Morneault
Reacted by Simone Lusenti, Evan Kozliner, Ben McClain, Anjan Biswas, Yurii Hizun, Richard Klotz, Karan Tikku, Martín Bermúdez and Jeremy LAURENT
Reacted by Juan Rivillas, Reza, APogiatzis, mayur741, Yurii Hizun and amartins-bounteous
@ryanlitalien I'm trying to do the same (API GW + Lambda) but via cloudformation. Would you mind posting a sharable version of your cloudformation template ?
thnx
@ryanlitalien
I am too facing difficulties with Lambda permission for the API Gateway. Would you be able to post a complete sam yaml for the permission with a proxy-any example?
@BradNation4Eva @haiko Unfortunately I don't have access to the source anymore. Essentially you'll need to explicitly add and set permissions within the sam, with the DependsOn so it's run after the API GW and Lambda are created. Good luck 👍
Now my question would be if this permission is always needed in an API / Lambda example. And if that is the case if it shouldn't be added to the examples.
Reacted by Haiko, Alex Gausman, yayayahei and Dmitrii Popov
If you are using APIGW Console Test button, then yes this problem still exists. But if you Curl the API or go using browser default SAM settings will work. This is a bug, and the workaround you suggested is only temporarily needed until we fix this.
@sanathkr
I've been experiencing the same issue with an ANY method*, when using a function name with a stage variable.
That is when using the configuration just as in the api_swagger_cors example in the documentation, and not just from the test button in the console, but when querying externally as well.
The resolution has been using the explicit ConfigLambdaPermission as described by ryanliatien above.
*no issues when using an explicit POST instead of ANY (this could be a red herring though)
The easiest way I have found testing these things, is to write a 'unit test' with a SAM Template and add it here. You can take the output and put it into CloudFormation and test (manually). This is how I normally test new additions before sending to CR and writing integ tests.
If you need further help, its easy to communicate through our slack channel (#samdev). Feel free to ping me there, makes this process faster instead of going back and forth on github issues for help :)
Well, I guess it's not that simple. Apparently the 'ANY' method is used elsewhere and changing it to '*' at that translation phase will break stuff. Here's what applying that patch caused in one of the tests:
Actually it needs to be deployed first; so once you see it merged to master
we can close this. We are working on a better local transform experience.
Once that's done you will be able to use new features sooner.
I recently had a similar issue and turned out to be a problem with my Events in AWS::Serverless::Function. My Path didn't match the one I had defined in the swagger file.
Reacted by Sam Bryan, Borislav Hadzhiev and Yurii Terletskyi
Has anyone tried to get this working with API Gateway in one region and lambda in another? I tried manually through the API Gateway console - and it works fine.
But when I try to generate the API Gateway through cloudformation, I get the following error:
Functions from 'us-west-1' are not reachable in this region ('us-west-2') (Service: AWSLambda; Status Code: 404; Error Code: ResourceNotFoundException;
The cloudformation template lives in us-west-2. We have our API Gateway there since Cognito is not available in us-west-1. But we'd like to have our lambdas in us-west-1.
The solution from @lusentis is the correct one. Use FunctionName: !Ref <function> instead of a DependsOn attribute. and the dependency tree will be automatically correct.
I am receiving 500 internal server error (Invalid permissions on Lambda function) . API gateway in one aws account and Lambda in another (same region). APIgateway code created using terraform .
error is gone when i delete the method and create a new one. Any idea how can we implement or fix this in terraform
Estou recebendo o erro 500 do servidor interno (permissões inválidas na função Lambda). Gateway de API em uma conta da AWS e Lambda em outra (mesma região). Código do APIgateway criado usando o Terraform.
o erro desaparece quando eu excluo o método e crio um novo. Alguma ideia de como podemos implementar ou consertar isso no Terraform
olha tudo bem, você descobriu a causa do problema?
Activity
sanathkr commentedon Jan 26, 2017
Where is the actual error? Does it happen when you make HTTP request to the API, say via Curl?
gpuettmann commentedon Jan 31, 2017
...yes, the error occurs, when I test the function, Error-Message:
"Tue Jan 31 14:52:20 UTC 2017 : Execution failed due to configuration error: Invalid permissions on Lambda function
Tue Jan 31 14:52:20 UTC 2017 : Method completed with status: 500"
sanathkr commentedon Feb 2, 2017
This error is on the APIGateway Web Console UI right? If so, I think this is a known problem
ryanlitalien commentedon Apr 24, 2017
Hi @sanathkr , I'm experiencing the same problems as the others here. Hopefully I can provide some more info.
I have a SAM with an API and 3 lambdas. Everything is deployed successfully and connected using stage variables as well. My API cannot talk to the lambda because of the permissions issue mentioned above.
I was able to click to change the lambda:

and then this is the modal that popped:
After I said "OK", the lambda was reachable via API Gateway.
In addition, since I'm using a stage variable, it provided an extra message:
Is there a step missing when the
AWS::Serverless::Apiis created to access the lambdas?ryanlitalien commentedon Apr 24, 2017
Corresponding AWS link regarding this issue: https://forums.aws.amazon.com/thread.jspa?threadID=217143
ryanlitalien commentedon Apr 26, 2017
@gpuettmann, @squareomatic Hey, I was able to get this to work by applying permissions on the lambda. I added this config to the sam yaml:
BadriRaghunathan commentedon Oct 25, 2017
@ryanlitalien I'm trying to do the same (API GW + Lambda) but via cloudformation. Would you mind posting a sharable version of your cloudformation template ?
thnx
haiko commentedon Nov 20, 2017
@ryanlitalien
I am too facing difficulties with Lambda permission for the API Gateway. Would you be able to post a complete sam yaml for the permission with a proxy-any example?
ryanlitalien commentedon Nov 20, 2017
@BradNation4Eva @haiko Unfortunately I don't have access to the source anymore. Essentially you'll need to explicitly add and set permissions within the sam, with the
DependsOnso it's run after the API GW and Lambda are created. Good luck 👍luebken commentedon Nov 30, 2017
I ran into the same issue and fixed it thanks to @ryanlitalien . You can see a simple example here: https://github.com/luebken/hello-sam
Now my question would be if this permission is always needed in an API / Lambda example. And if that is the case if it shouldn't be added to the examples.
haiko commentedon Dec 2, 2017
Works for me, thanks for sharing!
sanathkr commentedon Dec 2, 2017
If you are using APIGW Console Test button, then yes this problem still exists. But if you Curl the API or go using browser default SAM settings will work. This is a bug, and the workaround you suggested is only temporarily needed until we fix this.
If you are using separate Swagger, make sure you add the APIs to the events section as well. This will make SAM add correct Lambda::Permissions. See https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/api_swagger_cors/template.yaml#L24-L35
jsancho commentedon Dec 30, 2017
@sanathkr
I've been experiencing the same issue with an ANY method*, when using a function name with a stage variable.
That is when using the configuration just as in the
api_swagger_corsexample in the documentation, and not just from the test button in the console, but when querying externally as well.The resolution has been using the explicit
ConfigLambdaPermissionas described by ryanliatien above.*no issues when using an explicit POST instead of ANY (this could be a red herring though)
15 remaining items
jfuss commentedon Apr 25, 2018
@blade2005 Send a PR!
The easiest way I have found testing these things, is to write a 'unit test' with a SAM Template and add it here. You can take the output and put it into CloudFormation and test (manually). This is how I normally test new additions before sending to CR and writing integ tests.
If you need further help, its easy to communicate through our slack channel (#samdev). Feel free to ping me there, makes this process faster instead of going back and forth on github issues for help :)
villasv commentedon May 23, 2018
If no one picks up @blade2005 until June, I guess I'll give it a try.
villasv commentedon May 29, 2018
I applied a similar patch and it broke several tests already (not so "unit"ary heh). Gonna spend some time fixing them before even adding a new one.
villasv commentedon May 29, 2018
Well, I guess it's not that simple. Apparently the 'ANY' method is used elsewhere and changing it to '*' at that translation phase will break stuff. Here's what applying that patch caused in one of the tests:
So I guess that's not the best place to fix the issue.
Perhaps it should be fixed only in the relevant line mentioned by @jfuss:
resource = '${__ApiId__}/' + '${__Stage__}/' + self.Method.upper() + pathvillasv commentedon Jun 8, 2018
I believe this issue can be closed since #449 was merged.
brettstack commentedon Jun 8, 2018
beary commentedon Sep 6, 2018
I meet this problem when using lambda authorizer,
This is my template.yml
As you can see, I have specify the role which trust apigateway service to all the functions.
/account/testworks fine but/account/resourcereportssteven-gong commentedon Feb 7, 2019
Hi, @beary
I got the same permission issue for the authorizer lambda function, have you got any solution yet?
Cheers
beary commentedon Feb 9, 2019
@steven-gong I found solution but I fogot it...
Now I use serverless instead of aws-sam-cli.
It looks like
or
repinel commentedon Jun 13, 2019
I recently had a similar issue and turned out to be a problem with my
EventsinAWS::Serverless::Function. MyPathdidn't match the one I had defined in the swagger file.uclaeagit commentedon Sep 17, 2019
Has anyone tried to get this working with API Gateway in one region and lambda in another? I tried manually through the API Gateway console - and it works fine.
But when I try to generate the API Gateway through cloudformation, I get the following error:
The yaml in the CF template looks like this:
The cloudformation template lives in us-west-2. We have our API Gateway there since Cognito is not available in us-west-1. But we'd like to have our lambdas in us-west-1.
andriesss commentedon Jun 4, 2020
The solution from @lusentis is the correct one. Use
FunctionName: !Ref <function>instead of aDependsOnattribute. and the dependency tree will be automatically correct.pinkyrevathy commentedon Feb 2, 2024
I am receiving 500 internal server error (Invalid permissions on Lambda function) . API gateway in one aws account and Lambda in another (same region). APIgateway code created using terraform .
error is gone when i delete the method and create a new one. Any idea how can we implement or fix this in terraform
techlab-tiago commentedon Feb 18, 2025
olha tudo bem, você descobriu a causa do problema?