aws-apigateway: missing permission when adding nested resource on imported REST API Gateway backed by Lambda #24636
rodrigomata
started this conversation in
General
Replies: 2 comments 2 replies
-
If you export |
Beta Was this translation helpful? Give feedback.
0 replies
-
Moving this to discussion as this doesn't seem to be a relevant bug or feature request. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
Given a REST API Gateway stack that is constructed separately and then imported via
LambdaRestApi.fromRestApiAttributes
, if the resource specified on the attribute is not the root resource, and after creating a method and resource on the imported one, it will create wrong permissions for the lambda, as thesourceArn
won't match anymore.Expected Behavior
If the resource created is at the root level, it won't have any issues, since the created permission will be something like
/*/<method>/resource
; however, let's say that we have a base/root resource like/v1
which we create in the main REST API Gateway stack (StackA), and then we create another stack (StackB) importing resources from the main stack (StackA) and we want a GET resource with/users
but to live below/v1
so that the end result would be something like/v1/users
. The lambda function should have the permissions like/*/GET/v1/users
.Current Behavior
By using the expected behavior example, the actual behavior is that the resulting permission turns to be
/*/GET/users
, which is wrong and results into the request be denied because of permissions.Reproduction Steps
restApiId
andresourceId
from v1 resource (instead ofrestApiRootResourceId
that would point to the root resource) from StackA and using them to import RestApi with the methodfromRestApiAttributes
Possible Solution
I've found two possible workarounds for the issue, both involving adding a new Permission to the lambda integration:
Additional Information/Context
By using the workaround, the stack creates two zombie triggers that are unusable:

CDK CLI Version
2.63.0
Framework Version
No response
Node.js Version
16.18.1
OS
MacOS
Language
Typescript
Language Version
No response
Other information
No response
Beta Was this translation helpful? Give feedback.
All reactions