I think may be encountering a bug in the rule_event method call

Okay, I’ve been struggling with what I think may be a bug in the rule_event resource and thought I’d surface it here before I head over to Github and submit it as an issue. I’m still learning my way around the Jets codebase and don’t think I’m quite in a place where I’d be able to submit a PR but if this does indeed look like a bug and you’d like to point me in the right direction I’d be happy to dig in and see if I can submit a PR. In the meantime, here’s what I’m seeing.

My “rule_event” call looks like so:

    description: "Checks for orders",
    detail_type: ['shopify_order_import']

When I attempt a deploy, I receive an error and my cloud formation is rolled back. After digging into a few things, I noticed that “detail_type” is converted to “detail-type” and if I have other attributes in that rule_event call with underscores like “line_items”, they get converted to camelCase as well like “lineItems”. Here’s the exact error message that I’m getting from CloudFormation: https://www.dropbox.com/s/t86mhpsgantv6g2/Screen%20Shot%202021-03-06%20at%206.29.40%20PM.png?dl=0 and here’s a screenshot of a what this rule looks like in Event Bridge: https://www.dropbox.com/s/zvxoc2dkd0qorjl/Screen%20Shot%202021-03-06%20at%206.29.48%20PM.png?dl=0

I should note that the last screenshot I shared was when I took a different approach to applying that rule using this pattern format: https://www.dropbox.com/s/ufrhv6pisfkrjs4/Screen%20Shot%202021-03-06%20at%206.40.08%20PM.png?dl=0 but the outcome did result in some formatting that did not match my rules. Any who, I’m going to try a different approach and try to use the full “resource” approach and see if that will at least get me operational but would love any insight you might have @tung.

Please let me know if I can provide any additional information to help troubleshoot. Thanks! :slight_smile:

Okay, hopefully this will help explain a bit more of what I’m seeing. Here is my code: https://www.dropbox.com/s/z7evebac9e3gkm1/Screen%20Shot%202021-03-06%20at%207.01.33%20PM.png?dl=0. I went with the full format of “resource” just to make sure it was nothing specific to the rule_event call.

And here’s the template that is generated as a result: https://www.dropbox.com/s/4y2q77q8zireofs/Screen%20Shot%202021-03-06%20at%207.00.48%20PM.png?dl=0. Unfortunately, you’ll specifically notice that “line_items” and “variant_id” are converted to “lineItems” and “variantId”. From what I can tell, this means that my patterns don’t seem to match what I’m trying to match.

Does that make sense?

Okay, some more info in the event that it helps :slight_smile: I think I’ve finally confirmed my own suspicions. Here’s an updated code snippet: https://www.dropbox.com/s/5rb3m5rglqg737a/Screen%20Shot%202021-03-06%20at%208.01.07%20PM.png?dl=0. That pattern does indeed match an event as ‘email’ does not get camelCased.

However, if I attempt to match on another attribute in my event “contact_email” like so: https://www.dropbox.com/s/5rb3m5rglqg737a/Screen%20Shot%202021-03-06%20at%208.01.07%20PM.png?dl=0, that gets converted to “contactEmail” in my cloudformation template: https://www.dropbox.com/s/q1e56p05chkraqp/Screen%20Shot%202021-03-06%20at%208.03.19%20PM.png?dl=0 and never matches my event, even though it should: https://www.dropbox.com/s/mmo0i9jlfabo933/Screen%20Shot%202021-03-06%20at%208.04.03%20PM.png?dl=0

As far as I can tell, I’m not too far off base here but if I could possibly get another set of eyes on it, it would be appreciated :slight_smile:


Some additional information. If I manually edit the event pattern in Event Bridge: https://www.dropbox.com/s/u6mtpp7q4e4ovz7/Screen%20Shot%202021-03-07%20at%201.52.54%20AM.png?dl=0 the event matches and I get the appropriate results.

I’m currently digging deeper into the Jets codebase to see if I can figure out where this transformation is happening

Okay, I’m gathering this is where it’s all going down: https://github.com/tongueroo/cfn_camelizer/blob/master/lib/cfn_camelizer.rb :slight_smile: It seems as though it’s intentional but I’m not certain it makes it easy to match on keys that use underscores if that’s the case.

I guess my only option in the meantime is to try and transform my keys before putting the entries onto EventBridge. Certainly welcome any pointers.

Okay, final update for the evening. I hope you don’t mind all the messages, hopefully they’ll be helpful to someone along the way. I ended up deciding to transform my input before calling put_events to place my payload onto EventBridge.

To do this, I call deep_transform_keys{|k| k.camelize(:lower)} on my input object which transforms my object keys from something like “contact_email” to “contactEmail”. It feels a little hacky but doesn’t seem to cause much problem and I’m getting matches on my event pattern now which is all I was trying to accomplish :slight_smile:

Given your attention to detail on all of this, I’m guessing perhaps the decision was intentional but it might be worth calling out somewhere in the documentation if that is indeed the case. I’m happy to chip in there if it helps.

Now time for sleep. Cheers :beers: