Skip to content

Commit 9734bb4

Browse files
feat(apigatewayv2-integrations): auto-include EventBusName in HttpEventBridgeIntegration default parameter mapping (#36780)
… ### Issue # (if applicable) Closes #36775. ### Reason for this change The current implementation of `HttpEventBridgeIntegration` requires users to redundantly specify `EventBusName` in the parameter mapping, even though this information is already available in the `eventBusRef` object. This creates unnecessary boilerplate and potential for errors when the event bus name is specified in two places that could become out of sync. **Current behavior (redundant):** ```typescript new HttpEventBridgeIntegration('WebhookInt', { eventBusRef: props.eventBus.eventBusRef, // Contains eventBusName parameterMapping: new ParameterMapping() .custom('EventBusName', props.eventBus.eventBusName), // ❌ Redundant! }); ``` **Expected behavior:** ```typescript new HttpEventBridgeIntegration('WebhookInt', { eventBusRef: props.eventBus.eventBusRef, // ✅ EventBusName auto-included }); ``` Since `eventBusRef` is required and already contains `eventBusName`, there's no scenario where these should differ. The CDK should automatically extract and include `EventBusName` in the default parameter mapping to improve developer experience. ### Description of changes **Implementation changes:** - Modified `createDefaultParameterMapping()` in `HttpEventBridgeIntegration` to automatically include `EventBusName` by extracting it from `this.props.eventBusRef.eventBusName` - Updated the method comment to explain that `EventBusName` is automatically included to avoid redundant configuration - Updated JSDoc for `parameterMapping` property to document that `EventBusName` is now included by default **Test changes:** - Updated unit test `'default'` to verify that `EventBusName` is included in the default parameter mapping with the correct value from `eventBusRef` - Added comments to integration tests documenting the automatic inclusion behavior **Files modified:** - `packages/aws-cdk-lib/aws-apigatewayv2-integrations/lib/http/eventbridge.ts` - Core implementation - `packages/aws-cdk-lib/aws-apigatewayv2-integrations/test/http/eventbridge.test.ts` - Unit tests - `packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/http/integ.eventbridge.ts` - Integration tests ### Describe any new or updated permissions being added No new or updated IAM permissions are required. The change only affects how the parameter mapping is constructed - the underlying EventBridge `PutEvents` API call and required permissions remain unchanged. ### Description of how you validated changes **Unit tests:** - Updated the existing `'default'` test case to verify that `EventBusName` is included in `RequestParameters` with the correct value from the event bus - Verified that the test correctly resolves `bus.eventBusName` to match the expected CloudFormation output - All existing tests continue to pass, ensuring backward compatibility **Integration tests:** - Reviewed integration test to ensure it will work correctly with the automatic `EventBusName` inclusion - Added documentation comments explaining the automatic behavior - The integration test sends requests with `Detail`, `DetailType`, and `Source` in the body, and `EventBusName` is now automatically included in the parameter mapping by the API Gateway integration **Manual validation:** - Verified that the implementation correctly extracts `eventBusName` from `eventBusRef` - Confirmed that custom `parameterMapping` still works as expected (test case `'with parameterMapping'` validates this) - Checked that the change is backward compatible - existing code with custom parameter mappings continues to work ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent f1bf405 commit 9734bb4

11 files changed

Lines changed: 2685 additions & 3386 deletions

File tree

‎packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/http/integ.eventbridge.js.snapshot/EventBridgeIntegrationIntegTestDefaultTestDeployAssert65D070E8.assets.json‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/@aws-cdk-testing/framework-integ/test/aws-apigatewayv2-integrations/test/http/integ.eventbridge.js.snapshot/EventBridgeIntegrationIntegTestDefaultTestDeployAssert65D070E8.template.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)