我如何在AWS CloudWatch告警状态更改时向EventBridge发送事件?

huangapple go评论63阅读模式
英文:

How can I send events to EventBridge upon AWS CloudWatch alarm status change?

问题

如何在警报状态更改时发送事件到EventBridge?

警报事件和EventBridge - 亚马逊云监控说这是可能的,但没有说明如何操作。

警报上可用的UI操作也不允许将EventBridge设置为操作。

我不想使用SNS。我需要通过EventBridge来触发特定操作。

英文:

How to send an Event to EventBridge on Alarm state change?

Alarm events and EventBridge - Amazon CloudWatch says it's possible but doesn't tell how to.

UI Actions available on alarm also doesn't let EventBridge to be set as an action.

I don't want to use SNS. I need to trigger specifically via EventBridge.

答案1

得分: 2

EventBridge不能作为警报的目标。相反,EventBridge是从AWS(以及可选地来自AWS合作伙伴和您的自定义事件)接收所有事件的总线。说到这一点,在将Cloudwatch的警报传递到EventBridge中,您需要执行以下步骤:

EventBridge->Rules->创建规则

事件源中选择AWS事件或EventBrige合作伙伴事件

示例事件中,您可以选择CloudWatch Alarm State Change,以便查看可以用来过滤事件的完整值列表。

事件模式中,您将选择:

AWS服务->CloudWatch->CloudWatch Alarm State Change

这将创建一个类似于此的事件模式:

{
  "source": ["aws.cloudwatch"],
  "detail-type": ["CloudWatch Alarm State Change"]
}

您将希望将其设置为特定的警报和状态,因此您应该至少添加resourcedetail.state部分,类似于:

{
  "source": ["aws.cloudwatch"],
  "detail-type": ["CloudWatch Alarm State Change"],
  "resources": ["arn:aws:cloudwatch:us-east-1:123456789012:alarm:ServerCpuTooHigh"],
  "detail": {
    "state": {
      "value": ["ALARM"]
    }
  }
}
英文:

EventBridge cannot be a target for the Alarm. Instead, EventBridge is the bus that receives all the events from AWS (and optionally from AWS Partners and your custom events). That being said, in order to catch the Alarm from Cloudwatch into EventBridge, you have to go to:

EventBridge->Rules->Create rule

In Event source, choose AWS events or EventBrige partner events

In Sample event you can choose CloudWatch Alarm State Change so you can see a full list of values that you can use to filter your events.

In Event pattern you will choose:

AWS services -> CloudWatch -> CloudWatch Alarm State Change

This will create an Event pattern like this:

{
  "source": ["aws.cloudwatch"],
  "detail-type": ["CloudWatch Alarm State Change"]
}

You will want to set it for specific alarm and state, so you should add at least resource and detail.state sections, something like:

{
  "source": ["aws.cloudwatch"],
  "detail-type": ["CloudWatch Alarm State Change"],
  "resources": ["arn:aws:cloudwatch:us-east-1:123456789012:alarm:ServerCpuTooHigh"],
  "detail": {
    "state": {
      "value": ["ALARM"]
    }
  }
}

huangapple
  • 本文由 发表于 2023年5月22日 14:52:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303646.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定