- Newest
- Most votes
- Most comments
To create EventBridge rules that match on specific elements within your array, you'll need to understand how EventBridge handles array matching. When an event pattern field contains an array, EventBridge matches the event if the intersection of the pattern array and the event array is non-empty - meaning if any value in your pattern array matches any value in the event array.
However, your current event structure presents a challenge. The array is under a field called "$unknown" and contains objects with multiple properties (NS, N, U, A, V, TS). EventBridge's array matching works best when you're matching on simple values or when the array elements themselves are the values you want to match.
For your use case, I'd recommend restructuring your event data before it reaches EventBridge. Instead of having all metrics in a single array under "$unknown", consider transforming the event in your IoT rule to create separate top-level fields for the metrics you care about. For example:
{
"NumberOfComponentsBroken": 0,
"NumberOfComponentsErrored": 0,
"thingName": "sightio-tdcoffice",
"detailtype": "Telemetry",
"source": "greengrass.telemetry"
}
With this structure, you can create an EventBridge rule with an event pattern like:
{
"source": ["greengrass.telemetry"],
"detail": {
"NumberOfComponentsBroken": [{"numeric": [">", 0]}]
}
}
This would trigger whenever NumberOfComponentsBroken is greater than 0. You can use comparison operators like "numeric" with conditions such as ">", ">=", "<", "<=", or "=" to match on specific value ranges.
Alternatively, if you prefer to use CloudWatch for this monitoring, you could send these metrics directly to CloudWatch Metrics and create CloudWatch Alarms based on threshold values, which might be more straightforward for numeric monitoring scenarios like component health status.
Sources
Matching on multiple values for an event field in Amazon EventBridge - Amazon EventBridge
Creating rules in Amazon EventBridge - Amazon EventBridge
I'm open to restructuring the object, but I am trying to avoid creating another component to run on the device. Is there a way to restructure this data through more IoT rules?
Relevant content
- asked 14 days ago
- asked 3 years ago
