Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-events): EventPattern support for wildcard filters #28462

Closed
2 tasks
tyyzqmf opened this issue Dec 22, 2023 · 10 comments · Fixed by #32063
Closed
2 tasks

(aws-events): EventPattern support for wildcard filters #28462

tyyzqmf opened this issue Dec 22, 2023 · 10 comments · Fixed by #32063
Labels
@aws-cdk/aws-events Related to CloudWatch Events effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@tyyzqmf
Copy link

tyyzqmf commented Dec 22, 2023

Describe the feature

As this whats-new: Amazon EventBridge announces support for wildcard filters in rules

Use Case

We can set event pattern in web console:

{
  "detail-type": ["Step Functions Execution Status Change"],
  "resources": [{
    "wildcard": "arn:aws:states:us-east-1:111122223333:execution:xxx:yyy*"
  }],
  "source": ["aws.states"]
}

But can not create this rule by CDK:

const ruleState = new Rule(this, 'ListenStateStatusChange', {
      description: 'Rule for listen SFN state machine status change',
      eventPattern: {
        source: ['aws.states'],
        detailType: ['Step Functions Execution Status Change'],
        resources: [`{ "wildcard": "arn:${Aws.PARTITION}:states:${Aws.REGION}:${Aws.ACCOUNT_ID}:execution:xxx:yyy*" }`],
      },
    });

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.81.0

Environment details (OS name and version, etc.)

linux

@tyyzqmf tyyzqmf added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 22, 2023
@github-actions github-actions bot added the @aws-cdk/aws-events Related to CloudWatch Events label Dec 22, 2023
@pahud pahud self-assigned this Dec 22, 2023
@pahud
Copy link
Contributor

pahud commented Dec 22, 2023

But can not create this rule by CDK:

What error message was that?

Can you share the synthesized output specifically for the Rule resource?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 22, 2023
@pahud pahud removed their assignment Dec 22, 2023
@pahud pahud added the effort/medium Medium work item – several days of effort label Dec 22, 2023
@tim-finnigan
Copy link

Have you tried using the Match class? https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_events.Match.html

This came up in a similar issue earlier this year: #25424

@tim-finnigan tim-finnigan added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Dec 22, 2023
@tyyzqmf
Copy link
Author

tyyzqmf commented Dec 23, 2023

@pahud this is synthesized output:

{
  "EventPattern": {
    "source": [
      "aws.states"
    ],
    "detail-type": [
      "Step Functions Execution Status Change"
    ],
    "resources": [
      {
        "Fn::Join": [
          "",
          [
            "{ \"wildcard\": \"arn:",
            {
              "Ref": "AWS::Partition"
            },
            ":states:",
            {
              "Ref": "AWS::Region"
            },
            ":",
            {
              "Ref": "AWS::AccountId"
            },
            ":execution:xxx:yyy*\" }"
          ]
        ]
      }
    ]
  }
}

@tyyzqmf
Copy link
Author

tyyzqmf commented Dec 23, 2023

Have you tried using the Match class? https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_events.Match.html

This came up in a similar issue earlier this year: #25424

@tim-finnigan Yes, I had try it. But there is no event pattern matcher can support for wildcard filter.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 23, 2023
@pahud
Copy link
Contributor

pahud commented Dec 26, 2023

Yes it can deploy and I see this from the console

{
  "detail-type": ["Step Functions Execution Status Change"],
  "resources": ["{ \"wildcard\": \"arn:aws:states:us-west-2:903779448426:execution:xxx:yyy*\" }"],
  "source": ["aws.states"]
}

while this is expected:

{
  "detail-type": ["Step Functions Execution Status Change"],
  "resources": [{
    "wildcard": "arn:aws:states:us-east-1:111122223333:execution:xxx:yyy*"
  }],
  "source": ["aws.states"]
}

I guess the Match would need to support wildcard but before that you can use this workaround:

    const ruleState = new events.Rule(this, 'ListenStateStatusChange', {
      description: 'Rule for listen SFN state machine status change',
      eventPattern: {
        source: ['aws.states'],
        detailType: ['Step Functions Execution Status Change'],
        resources: [`{ "wildcard": "arn:${Aws.PARTITION}:states:${Aws.REGION}:${Aws.ACCOUNT_ID}:execution:xxx:yyy*" }`],
      },
    });

    (ruleState.node.defaultChild as events.CfnRule).addPropertyOverride('EventPattern.resources.0', 
     { wildcard: `arn:${Aws.PARTITION}:states:${Aws.REGION}:${Aws.ACCOUNT_ID}:execution:xxx:yyy*` },
    );

Let me know if it works for you.

@tyyzqmf
Copy link
Author

tyyzqmf commented Dec 27, 2023

@pahud Thank you for your prompt. I have successfully created the rule following code:

    const cfnRule = rule.node.defaultChild as events.CfnRule;
    cfnRule.addOverride('Properties.EventPattern.resources', [
     {wildcard: `arn:${Aws.PARTITION}:states:${Aws.REGION}:${Aws.ACCOUNT_ID}:execution:xxx:yyy*`},
    ]);

@pahud
Copy link
Contributor

pahud commented Dec 27, 2023

@tyyzqmf Awesome! I am leaving this issue open until we have better implementation in CDK.

@jk2l
Copy link

jk2l commented Sep 11, 2024

encountered this issue too

Copy link

github-actions bot commented Dec 5, 2024

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.

1 similar comment
Copy link

github-actions bot commented Dec 5, 2024

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 Dec 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/aws-events Related to CloudWatch Events effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
4 participants