Skip to content

Conversation

@jasdeepbhalla
Copy link
Contributor

@jasdeepbhalla jasdeepbhalla commented Oct 17, 2025

Issue #35714

Closes #35714

Reason for this change

The CDK currently lacks a high-level L2 construct to enable HTTP API integration with EventBridge PutEvents. Users must manually configure the integration, including IAM roles and parameter mapping, which adds complexity and potential for misconfiguration. This feature simplifies usage and aligns with other existing HTTP API integrations like SQS.

Description of changes

  • Added HttpEventBridgeIntegration class extending HttpRouteIntegration.
  • Introduced HttpEventBridgeIntegrationProps interface with required parameters: detail, detailType, source; and optional parameters: eventBusName, resources, time, region, traceHeader, invocationRole, description, timeout.
  • Automatically creates the IAM role with the necessary permissions if invocationRole is not provided.
  • Implements parameter mapping for EventBridge PutEvents API.
  • Added unit tests to verify integration behavior.
  • Updated documentation to include usage examples.

Example usage:

const stack = new Stack();
const bus = new EventBus(stack, 'Events');
const api = new HttpApi(stack, 'HttpApi');
api.addRoutes({
  path: '/default',
  methods: [apigwv2.HttpMethod.POST],
  integration: new HttpEventBridgeIntegration('defaultIntegration', {
    eventBus: bus,
  }),
});

api.addRoutes({
  path: '/put-events',
  methods: [apigwv2.HttpMethod.POST],
  integration: new HttpEventBridgeIntegration('putEventsIntegration', {
    eventBus: bus,
    subtype: apigwv2.HttpIntegrationSubtype.EVENTBRIDGE_PUT_EVENTS,
  }),
});

Description of how you validated changes

  • Added unit tests covering successful integration creation and parameter mapping.
  • Manual testing with a sample stack to verify events are sent correctly to EventBridge.

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 17, 2025 03:39
@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Oct 17, 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)

@aws-cdk-automation aws-cdk-automation dismissed their stale review October 17, 2025 07:43

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

*
* @default HttpIntegrationSubtype.EVENTBRIDGE_PUT_EVENTS
*/
readonly subtype?: apigwv2.HttpIntegrationSubtype;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we fix the HttpIntegrationSubtype.EVENTBRIDGE_PUT_EVENTS? Otherwise, you could pass another subtype here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that’s another valid approach. Keeping it this way allows us to easily extend support to other subtypes in the future.

If an unknown subtype is provided, we already handle it by throwing an error, so that scenario is covered.

Copy link
Contributor

@jolo-dev jolo-dev Oct 17, 2025

Choose a reason for hiding this comment

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

Yeah, I understand.
But from the DX-perspective the developer does not know that only HttpIntegrationSubtype.EVENTBRIDGE_PUT_EVENTS is possible.

Perhaps you could create a new type

type HttpEventBridgeIntegrationSubtype = 'EVENTBRIDGE_PUT_EVENTS'  // then you could use a discreminator to add more events;

export interface HttpEventBridgeIntegrationProps {
  // ..
  readonly subtype?: HttpEventBridgeIntegrationSubtype;
  // ...
}

export class HttpEventBridgeIntegration extends apigwv2.HttpRouteIntegration {
  private readonly subtype: apigwv2.HttpIntegrationSubtype;
  /**
   * @param id id of the underlying integration construct
   * @param props properties to configure the integration
   */
  constructor(
    id: string,
    private readonly props: HttpEventBridgeIntegrationProps,
  ) {
    super(id);
    this.subtype = this.props.subtype;
  }

  public bind(options: apigwv2.HttpRouteIntegrationBindOptions): apigwv2.HttpRouteIntegrationConfig {
    // ...

    return {
      payloadFormatVersion: apigwv2.PayloadFormatVersion.VERSION_1_0,
      type: apigwv2.HttpIntegrationType.AWS_PROXY,
      subtype: apigwv2.HttpIntegrationSubtype[this.props.subtype ?? 'EVENTBRIDGE_PUT_EVENTS'], // <-- this needs to be changes
      credentials: apigwv2.IntegrationCredentials.fromRole(invokeRole),
      connectionType: apigwv2.HttpConnectionType.INTERNET,
      parameterMapping: this.props.parameterMapping ?? this.createDefaultParameterMapping(options.scope),
    };
  }

}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good Point, let me update the code

@jolo-dev
Copy link
Contributor

jolo-dev commented Oct 17, 2025

@jasdeepbhalla Ah, you were faster than me :D
Good work. I would have done one thing differently.

@jasdeepbhalla jasdeepbhalla force-pushed the support_putevents_in_apigatewayv2_eventbridge_integrations branch from 7a23efc to 3cb751f Compare October 29, 2025 04:01
@jasdeepbhalla
Copy link
Contributor Author

@jolo-dev @pahud This PR is ready for review!

@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Oct 29, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Nov 18, 2025
*
* @default HttpIntegrationSubtype.EVENTBRIDGE_PUT_EVENTS
*/
readonly subtype?: HttpIntegrationSubtypeEventBridgePutEvents;
Copy link
Contributor

Choose a reason for hiding this comment

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

This subtype need to take something more general so if in the future they add another type we can have it without breaking the backward compatibility.

You can find the same principle applied here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah agreed 👍

switch (this.subtype) {
case apigwv2.HttpIntegrationSubtype.EVENTBRIDGE_PUT_EVENTS:
return new apigwv2.ParameterMapping()
.custom('EventBusName', this.props.eventBus.eventBusName)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any reason for adding non required field for the default parameters? In the case of not sending any bus name falling back to the default one, i believe we can get the information needed by From functions

Also can we add in code comment the link for the required parameters field table, this will help maintainers in case there's a problem to fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, you are right, we should just keep the default ones in there. Updated the code and added comments to keep future readers informed about the required params

/**
* EventBridge event bus that integrates with API Gateway
*/
readonly eventBus: events.IEventBus;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a new thing in CDK, from now on we're using refs as much as possible, so can you change it to use IEventBusRef

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thats a good point, updated.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 8, 2026
@mergify mergify bot dismissed gasolima’s stale review January 10, 2026 03:17

Pull request has been modified.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 10, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results48 ran48 passed
TestResult
No test annotations available

@github-actions
Copy link
Contributor

github-actions bot commented Jan 10, 2026

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates48 ran48 passed
TestResult
No test annotations available

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 10, 2026
@gasolima gasolima added the pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots. label Jan 12, 2026
@gasolima gasolima temporarily deployed to deployment-integ-test January 12, 2026 11:04 — with GitHub Actions Inactive
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 12, 2026
@mergify
Copy link
Contributor

mergify bot commented Jan 12, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Jan 12, 2026

Merge Queue Status

✅ The pull request has been merged at a3f49d9

This pull request spent 3 hours 19 minutes 10 seconds in the queue, including 1 hour 18 minutes 28 seconds running CI.
The checks were run in-place.

Required conditions to merge

@mergify mergify bot temporarily deployed to deployment-integ-test January 12, 2026 13:39 Inactive
@mergify mergify bot merged commit d879e4d into aws:main Jan 12, 2026
24 of 25 checks passed
@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 Jan 12, 2026
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 effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apigatewayv2-integrations: Add support for PutEvents to Eventbridge integration

4 participants