[APIGateway] LambdaIntegration: Add option to create a single trigger/permission with wildcards only instead of one for each ApiGateway Resource
See original GitHub issueFor the Lambda ApiGateway integration, add an option to prefer a single wildcard trigger/integrationPermission instead of multiple triggers/integrationPermissions for each URL/endpoint/resource defined in the ApiGateway.
Currently the created triggers in the AWS console looks like that:
arn:aws:execute-api:us-east-1:123:api_id/prod/GET/v1/parent_res_1/*
arn:aws:execute-api:us-east-1:123:api_id/prod/POST/v1/parent_res_1/*
arn:aws:execute-api:us-east-1:123:api_id/prod/GET/v1/parent_res_2/*
...
The requested feature would allow to have something like that instead:
arn:aws:execute-api:us-east-1:123:api_id/*
Use Case
In case of APIs with a larger amount of urls/endpoints/resources, it is likely to get a “The final policy size (XXX) is bigger than the limit (20480)
” error.
In our case, we run into that for an API with around 15 resources and worked around temporarily by setting LambdaIntegrationOptions.allowTestInvoke
to false
. This cut the number of triggers/IntegrationPermissions in half and the policy didn’t hit the limit anymore.
However, we would prefer leaving allowTestInvoke
to true
.
Moreover as the API grows over time, we will likely run into the same issue again later: the faster the API grows, the sooner. Implementing something like described in https://github.com/aws/aws-cdk/issues/5774#issuecomment-609583801 (also see below) currently seems to be something like a last resort for us.
Implication of the current state of CDK in this respect for us is that the CDK ApiGateway -> LambdaIntegration cannot be easily used for APIs with a considerable amount of endpoints because the CDK stack will break sooner or later when adding more resources to the APIGateway.
Proposed Solution
- Add
boolean
optionsingleWildcardTrigger
orsingleWildcardIntegrationPermission
toaws_cdk.aws_apigateway.LambdaIntegrationOptions
. - Per default, it is
false
and everything works like as it does currently. - In case of
true
, only a single trigger with wildcards is generated (see above). - With the existing
allowTestInvoke
option, there is already an option which works globally an all tiggers/integrationPermissions as well. So something very similar is already available.
Other
There is a similar (duplicate?) issue which as been closed already https://github.com/aws/aws-cdk/issues/5774 (closed https://github.com/aws/aws-cdk/issues/5774#issuecomment-594902199 by AWS). The discussions in the end (after closing by AWS) are about workarounds (subclassing CDK) for something which seems to be missing as a feature, thus I created a new issue. Feel free to reopen the original one and add this as a duplicate.
Please also check https://github.com/aws/aws-cdk/issues/5774#issuecomment-609583801 which has been added after closing the issue. This comment describes the problem exactly the same as we see it.
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Reactions:16
- Comments:29 (5 by maintainers)
Top GitHub Comments
Expecting for this to be fixed also!
Author of the comment that is referenced in this ticket. It has been a few versions since that was posted and no longer works. I took some inspiration from @nija-at comment above. Rather extending the class as I did in the old method than using Aspects that apply it over all the whole API GW methods. So my alternative updated version that seems to work: