Open tyyzqmf opened 9 months ago
But can not create this rule by CDK:
What error message was that?
Can you share the synthesized output specifically for the Rule
resource?
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: https://github.com/aws/aws-cdk/issues/25424
@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*\" }"
]
]
}
]
}
}
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.
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.
@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*`},
]);
@tyyzqmf Awesome! I am leaving this issue open until we have better implementation in CDK.
encountered this issue too
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:
But can not create this rule by CDK:
Proposed Solution
No response
Other Information
No response
Acknowledgements
CDK version used
2.81.0
Environment details (OS name and version, etc.)
linux