Skip to content

Conversation

cogwirrel
Copy link
Member

@cogwirrel cogwirrel commented Oct 9, 2025

Issue # (if applicable)

Fixes #9327
Fixes #19535

Reason for this change

The maximum Lambda permission policy size could be exceeded for APIs which reused the same Lambda function for multiple operations, as the integration added a new permission for each operation, scoped down to the specific operation.

Description of changes

This change updates both the REST and HTTP API lambda integrations to consolidate permissions when more than 10 permissions would be added for the same handler, creating a permission scoped to the entire API rather than the operation. The behaviour remains the same where individual lambdas are used for operations.

Note that we search for permissions within the route's parent stack for HTTP APIs, or within the API for REST APIs, and so it won't prevent the policy size being exceeded if the same lambda is reused cross-stack.

Describe any new or updated permissions being added

Permission for API Gateway to invoke the lambda is scoped to any resource/method/stage when a lambda is reused for multiple operations.

Description of how you validated changes

Unit tests, Integration tests

Added an integration test for both REST and HTTP (integ.lambda-permission-consolidation).

There are a lot of integration tests that now have updated snapshots since I've changed the logical ID for lambda permissions to include both the API and Handler IDs so that they can be identified for consolidation.

I wasn't able to get the following 2 integration tests to run:

  • aws-route53-targets/test/integ.api-gateway-domain-name.ts - there's a comment in here that mentions it doesn't work due to the reliance on a hardcoded domain name
  • aws-apigatewayv2-integrations/test/http/integ.lambda-permission-consolidation.ts - fails since the lambda permission tries to deploy prior to the imported lambda function - I'm not sure if this worked previously - can look into fixing this integration test if required

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team October 9, 2025 03:35
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p1 labels Oct 9, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@cogwirrel cogwirrel changed the title feat(apigateway): consolidate lambda permissions when reused for multiple operations fix(apigateway): consolidate lambda permissions when reused for multiple operations Oct 9, 2025
@cogwirrel cogwirrel force-pushed the feat/apigw-lambda-permission branch 2 times, most recently from 226ca0b to 5db887f Compare October 9, 2025 06:42
@cogwirrel cogwirrel had a problem deploying to deployment-integ-test October 9, 2025 06:42 — with GitHub Actions Error
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 9, 2025 06:44

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@cogwirrel cogwirrel force-pushed the feat/apigw-lambda-permission branch from 5db887f to fe3aa7f Compare October 9, 2025 07:57
@cogwirrel cogwirrel had a problem deploying to deployment-integ-test October 9, 2025 07:57 — with GitHub Actions Error
@cogwirrel cogwirrel force-pushed the feat/apigw-lambda-permission branch from fe3aa7f to 0a13599 Compare October 9, 2025 08:31
@cogwirrel cogwirrel had a problem deploying to deployment-integ-test October 9, 2025 08:31 — with GitHub Actions Error
…ple operations

The maximum Lambda permission policy size could be exceeded for APIs which reused
the same Lambda function for multiple operations, as the integration added a new
permission for each operation, scoped down to the specific operation.

This change updates both the REST and HTTP API lambda integrations to consolidate
permissions when more than 10 permissions would be added for the same handler, creating a
permission scoped to the entire API rather than the operation. The behaviour
remains the same where individual lambdas are used for operations.

Fixes aws#9327
Fixes aws#19535
@cogwirrel cogwirrel force-pushed the feat/apigw-lambda-permission branch from 0a13599 to 1062ca3 Compare October 9, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Projects

None yet

2 participants