question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The cloudformation for event pattern generated by cdk contains 'detailType' while it should generate the key as 'detail-type'

See original GitHub issue

Description of the bug: When i use Cdk the cloudformation template that is generated for the 'event pattern ’ in a CfnRule construct contains the key as ‘detailType’ rather than ‘detail-type’

Reproduction Steps

Use the following in a Cdk stack

const cbEventPattern :EventPattern ={

    source: [
        'aws.codebuild'
    ],
    detail: {
        'build-status': [
            'FAILED'
        ],
        'project-name':' some value'
    },      
    detailType: [
      'CodeBuild Build State Change'
  ],


}
  const codeBuildRule = new CfnRule(this, 'CodeBuildCloudWatchEventsRule', {
    description: 'Code Build cloudwatch events rule',
    eventPattern: cbEventPattern,
    name: '',
    state: 'ENABLED'
})

Error Log

Environment

  • CLI Version : 1.20.0
  • Framework Version:0.22
  • OS :Windows
  • Language :typescript

Other

I found the following link https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-events/lib/rule.ts#L348 although i see a solve is there it does not work.


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rektidecommented, Dec 8, 2021

@rix0rrr the docs for https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.CfnRule.html#eventpattern-1 are incredibly confusing:

Type: any

AWS::Events::Rule.EventPattern.

This is confusing but it gives the impression that it expects an EventPattern. The EventPattern docs helpfully clarify this is not the case, but the docs for CfnRule are quite confusing. EventPattern trying to correct the situation:

Important: this class can only be used with a Rule class. In particular, do not use it with CfnRule class: your pattern will not be rendered correctly. In a CfnRule class, write the pattern as you normally would when directly writing CloudFormation.
1reaction
enrico-usaicommented, Mar 12, 2021

I resolved this problem by passing a raw dictionary, rather than an EventPattern, given that event_pattern attribute can be Any:

     events.CfnRule(
            scope=self,
            id="xxx",
            event_pattern={
                "detail": {
                    "build-status": ["FAILED", "STOPPED", "SUCCEEDED"],
                    "project-name": [xxx],
                },
                "detail-type": ["CodeBuild Build State Change"],
                "source": ["aws.codebuild"],
            },
            state="ENABLED",
        )
Read more comments on GitHub >

github_iconTop Results From Across the Web

interface EventPattern · AWS CDK
In a CfnRule class, write the pattern as you normally would when directly writing CloudFormation. ... Represents the "detail-type" event field.
Read more >
AWS Lambda Events - Event Bridge - Serverless Framework
EventBridge Event. The EventBridge makes it possible to connect applications using data from external sources (e.g. own applications, SaaS) or AWS services.
Read more >
Connecting Event Busses Across AWS Accounts | Ben's Blog
Select your bus then click Actions→Send events. Selecting an event bus. On the page that opens, make sure the "Detail type" matches the...
Read more >
Automate Documenting API Gateways in EventCatalog
new Rule(this, `cfRule`, { eventBus: props.bus, eventPattern: { source: ["aws.cloudformation"], detailType: ["CloudFormation Stack Status Change ...
Read more >
EventBridge rule "anything-but" pattern - Stack Overflow
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html. "For an event pattern to match an event, the event must ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found