Aws-cdk: Fix EventPattern to be usable in CloudWatch Events Rules

Created on 21 Jun 2019  路  2Comments  路  Source: aws/aws-cdk

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.

  • I'm submitting a ...

    • [X] :beetle: bug report
    • [ ] :rocket: feature request
    • [ ] :books: construct library gap
    • [ ] :phone: security issue or vulnerability => Please see policy
    • [ ] :question: support request => Please see note at the top of this template.
  • What is the current behavior?
    If the current behavior is a :beetle:bug:beetle:: Please provide the steps to reproduce
    I can create a CloudWatch Event Rule that uses a Schedule as follows:

new events.Rule(this, "heartbeat_rule", {
      schedule: events.Schedule.expression("rate(30 minutes)"),
...
    });

But if I try to do that with an EventPattern, it is undefined. Example:

new events.Rule(this, "heartbeat_rule", {
      eventPattern: events.EventPattern.source([...]),
...
    });

events.EventPattern is undefined.

I can't figure out how to use an EventPattern though. I think maybe because it is an Interface, but nothing seem to implement that Interface.

  • What is the motivation / use case for changing the behavior or adding this feature?
    I want to create a CloudWatch Events Rule to receive GuardDuty events.

  • Please tell us about your environment:

    • CDK CLI Version: 0.35.0
    • Module Version: aws-events
    • OS: [all | Windows 10 | OSX Mojave | Ubuntu | etc... ]
    • Language: [all | TypeScript | Java | Python ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

@aws-cdaws-cloudwatch @aws-cdaws-events bug needs-reproduction p0

Most helpful comment

new events.Rule(this, "heartbeat_rule", {
      eventPattern: events.EventPattern.source([...]),
...
    });

I'm not even sure how the proposed code compiles. EventPattern is an interface, not a class, so this can't work in either TypeScript or JavaScript.

The correct syntax would be:

new events.Rule(this, "heartbeat_rule", {
      eventPattern: {
         source: ['...']
      }, 
    });

I will admit it's not super obvious that one uses a class constructor and the other one uses an object literal.

All 2 comments

new events.Rule(this, "heartbeat_rule", {
      eventPattern: events.EventPattern.source([...]),
...
    });

I'm not even sure how the proposed code compiles. EventPattern is an interface, not a class, so this can't work in either TypeScript or JavaScript.

The correct syntax would be:

new events.Rule(this, "heartbeat_rule", {
      eventPattern: {
         source: ['...']
      }, 
    });

I will admit it's not super obvious that one uses a class constructor and the other one uses an object literal.

Please reopen if you have further questions or remarks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mirazmamun picture mirazmamun  路  3Comments

EduardTheThird picture EduardTheThird  路  3Comments

abelmokadem picture abelmokadem  路  3Comments

eladb picture eladb  路  3Comments

ababra picture ababra  路  3Comments