aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.61k stars 3.91k forks source link

aws-events: Support 'null' values for event matching #8660

Open homanchou opened 4 years ago

homanchou commented 4 years ago

I'm trying to use AWS CDK to create an eventbridge rule.

The custom event will have a detail payload where I only want to match on events where order_item_id is null.

Here is the rule in cdk:

rule.addEventPattern({
  account: ['xxxxxxxxx'],
  detailType: ['inventory_adjusted'],
  detail: {
    'order_item_id': [null]
  }
})

And according to aws documentation, this is allowed:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html

To match events where the value of responseElements is null, use the following pattern, which would match the event example. { "detail": { "responseElements": [null] } }

However, when deploying with cdk I get this error:

development failed: ValidationError: [/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates >[/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates

And here is the cdk synth for the area around the rule:

EventPattern:
    account:
      - "xxxxxxxxx"
    detail-type:
      - inventory_adjusted
    detail:
      order_item_id:
        - null

Indeed it is null... which apparently isn't allowed in yaml template, but then how do I express this in CDK?

Reproduction Steps

create a rule that tries to match a null value for detail key

rule.addEventPattern({
  account: ['xxxxxxxxx'],
  detailType: ['inventory_adjusted'],
  detail: {
    'order_item_id': [null]
  }
})

Error Log

development failed: ValidationError: [/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates >[/Resources/sendinventoryadjustmentstolambda8954C2E5/Type/EventPattern/detail/order_item_id/0] 'null' values are not allowed in templates

Environment

node -v
v11.15.0

Other


This is :bug: Bug Report

rix0rrr commented 4 years ago

Good question. There's a good chance you can't. Looks like CloudFormation doesn't allow it, so the only way to make patterns like this is by using the API directly.

A custom resource would be the way to go.

mirgj commented 2 years ago

facing the same problem, can't use null value on the rule patterns

gergely-telgarec-ness commented 2 years ago

the same issue for me

peterwoodworth commented 2 years ago

If anyone would like to see support for this feature - I suggest reaching out to the CloudFormation coverage roadmap and creating an issue there if one doesn't exist yet. If CloudFormation were to implement this that would help us to create a better solution

brianarpie-forme commented 1 year ago

I wish this feature were supported.

thomasfinneyjr commented 1 year ago

Crazy that it’s not


From: brianarpie-forme @.> Sent: Thursday, January 12, 2023 4:56 PM To: aws/aws-cdk @.> Cc: Thomas Finney @.>; Manual @.> Subject: Re: [aws/aws-cdk] aws-events: Support 'null' values for event matching (#8660)

I wish this feature were supported.

— Reply to this email directly, view it on GitHubhttps://github.com/aws/aws-cdk/issues/8660#issuecomment-1381084125, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFCQCL5C6OASFN4ESQQWWMTWSCD2JANCNFSM4ODBY77Q. You are receiving this because you are subscribed to this thread.Message ID: @.***>