EventBridge Troubleshooting

0

Team, I'm trying to trigger an event based on the Ec2 tag "key" (Using EventBridge), But it fails.

{ "source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], "detail": { "state": ["running"], } }

This creates Event

whereas

{ "source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], "detail": { "state": ["running"], "tags": ["Name"] } }

Doesn't . I took the json based on the cloudtrail event

"tagSpecificationSet": {
        "items": [
            {
                "resourceType": "instance",
                "tags": [
                    {
                        "key": "Name",
                        "value": "Instance3"
                    }
                ]
            }
        ]
    },

Question,

  • I believe the problem is with event pattern matching and me not having right source
  • Side note, The sample event in event change not notification doesn't have TAG. So, Is it event possible to use filter event based on TAG with the EventBridge?
已提問 2 年前檢視次數 1059 次
1 個回答
-1
已接受的答案

The issue with your pattern is that you omitted the "Key" from there. It should be something like this (I based it on your example, did not check what the actual event looks like):

{
  "source": ["aws.ec2"],
  "detail-type": ["EC2 Instance State-change Notification"],
  "detail": { 
    "state": ["running"],
    "tagSpecificationSet": {
      "items": {
        "tags": {
          "key": ["Name"]
        }
      }
    }
  }
}

Note, the above pattern will match any tag that has a Key = Name. I assume you want to have a rule that matches Name = Instance3. This, i.e., correlating two attributes, is not supported by EventBridge Rules. If all you do is catch events regarding instances that have a tag names Name, this will work.

profile pictureAWS
專家
Uri
已回答 2 年前
  • That's a nice catch ! Unfortunately it didn't work . Probably do to with the actual event itself. How can log the events? (I tired DQL , But didn't work) Bcoz I'm now suspecting the Amazon EC2 State Change Event doesn't have "TAG" link https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#ec2_event_type . I'm looking for the event when EC2 is successfully created . Based on the event/json, so I can trigger the Run command (Target) by getting the Instance ID .

  • The issue was due to the event not having the TAG

    { "version": "0", "id": "XX", "detail-type": "EC2 Instance State-change Notification", "source": "aws.ec2", "account": "123", "time": "2022-09-05T10:42:39Z", "region": "us-east-1", "resources": [ "XX" ], "detail": { "instance-id": "XX", "state": "running" } }

  • EC2 Instance State-change Notification do not specify tags within the Event JSON, for available JSON properties please see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-instance-state-changes.html

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南