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
@cogwirrel cogwirrel force-pushed the feat/apigw-lambda-permission branch from 0a13599 to 1062ca3 Compare October 9, 2025 23:47
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

3 similar comments
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

Copy link
Member

@Abogical Abogical left a comment

Choose a reason for hiding this comment

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

Can you try recreating the integ test snapshots that are currently conflicting with the main branch atm? If a test fails, you can run the integ test with --dry-run and let me know which tests don't pass.

@Abogical Abogical self-assigned this Oct 23, 2025
…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 1062ca3 to 6fc77c1 Compare October 23, 2025 23:08
@mergify mergify bot dismissed Abogical’s stale review October 23, 2025 23:09

Pull request has been modified.

@cogwirrel
Copy link
Member Author

Thanks @Abogical ! :) I ran the integ tests and the only one that failed was aws-route53-targets/test/integ.api-gateway-domain-name.ts - this failed with the following error:

  FAILED     aws-route53-targets/test/integ.api-gateway-domain-name-apigateway-domain-name/DefaultTest (undefined/us-east-1) 50.814s
      Integration test failed: ToolkitError: ❌  aws-cdk-apigw-alias-integ failed: ToolkitError: The stack named aws-cdk-apigw-alias-integ failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE: Resource handler returned message: "The domain name you provided already exists. (Service: ApiGateway, Status Code: 400, Request ID: 55e00a5d-0f44-4a7a-8217-80a5f0eb9764) (SDK Attempt Count: 1)" (RequestToken: 0276c41e-32e9-9381-0cb8-8e16227f325a, HandlerErrorCode: AlreadyExists)

I've run that with --dry-run and committed the updated snapshots.

@cogwirrel
Copy link
Member Author

Looks like the security guardian check is failing on integ.prop-injectors.ts - I think this is unrelated to my change as it's flagging kms permissions. By the looks of things security guardian runs for any changed integ tests and since this change has updated the logical ids of lambda permissions, integ.prop-injectors.ts has some changes.

@Abogical Abogical added the pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots. label Oct 24, 2025
@Abogical Abogical had a problem deploying to deployment-integ-test October 24, 2025 09:47 — with GitHub Actions Error
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 24, 2025
@Abogical
Copy link
Member

@cogwirrel The security guardian is not a required workflow to pass atm.

@Abogical
Copy link
Member

Thanks for the change! The integration tests are now passing. I've asked for a security review of this PR.

@cogwirrel cogwirrel temporarily deployed to deployment-integ-test October 26, 2025 22:51 — with GitHub Actions Inactive
@cogwirrel cogwirrel requested a deployment to deployment-integ-test October 30, 2025 03:08 — with GitHub Actions Waiting
@Abogical Abogical removed the pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots. label Oct 30, 2025
Abogical

This comment was marked as outdated.

@Abogical Abogical self-requested a review November 5, 2025 13:18
Copy link
Member

@Abogical Abogical left a comment

Choose a reason for hiding this comment

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

Hi @cogwirrel , thank you for your contribution to this. However, we think that the approach you take for this PR is not a good idea from a security perspective. Consolidating lambda permissions to a permission that exposes the entire API is too permissive. This would only be acceptable if you can detect that ALL the methods use the same lambda integration, not just if its used more than 10 times.

I'm discussing possible alternative solutions to the issue with the team. I'll let you know once I have an update.

Copy link
Member

@Abogical Abogical left a comment

Choose a reason for hiding this comment

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

Hi @cogwirrel !

An alternative fix we can accept to this is to add an opt-in configuration property to the integration class. This property if set will have the integration add a permission per API instead of per route. This should fix the issue you mentioned while making it clear that the user intends to have the lambda permissions more permissive.

@cogwirrel
Copy link
Member Author

Hi @cogwirrel !

An alternative fix we can accept to this is to add an opt-in configuration property to the integration class. This property if set will have the integration add a permission per API instead of per route. This should fix the issue you mentioned while making it clear that the user intends to have the lambda permissions more permissive.

Thanks for reviewing! I've raised a separate PR which implements this suggestion here: #36021

@Abogical
Copy link
Member

Closing in favor of #36021.

@Abogical Abogical closed this Nov 12, 2025
@github-actions
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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 pr/needs-maintainer-review This PR needs a review from a Core Team Member

Projects

None yet

3 participants