简体   繁体   English

手动触发 AWS CloudWatch 事件

[英]Trigger AWS CloudWatch Event Manually

I have a event in CloudWatch, which is triggered once a day.我在 CloudWatch 中有一个事件,每天触发一次。 Is there a way to trigger the event manually (for testing purposes)?有没有办法手动触发事件(用于测试目的)?

...I realize I can increase the frequency of the event's triggering schedule. ...我意识到我可以增加事件触发时间表的频率。

If you have a cloudwatch alarm set up, using the AWS CLI you can, for testing purposes, set the alarm state of that alarm:如果您设置了 cloudwatch 警报,则出于测试目的,您可以使用 AWS CLI 设置该警报的警报 state:

aws cloudwatch set-alarm-state --alarm-name "myalarm" --state-value ALARM --state-reason "testing purposes"

see the docs here这里查看文档

Alternatively you can put a custom event , also using the CLI or the SDKs或者,您也可以使用 CLI 或 SDK 放置自定义事件

Another solution I found is to disable then re-enable the rule:我发现的另一个解决方案是禁用然后重新启用规则:

aws events disable-rule --name "my_scheduled_rule"
aws events enable-rule --name "my_scheduled_rule"

Perhaps not the best route but an option...也许不是最好的路线,但一个选择......

I haven't found (and I don't think it is possible) to trigger a scheduled trigger manually.我还没有找到(而且我认为不可能)手动触发预定的触发器。 But as danimal mentions you can put a custom event to trigger it.但是正如 danimal 提到的,您可以放置一个自定义事件来触发它。

# update your rule to trigger on a dummy-event source
# put-rule updates a rule if it exists or creates a new one if it doesn't
aws events put-rule --name "my-rule" --event-pattern "{\"source\":[\"karlanka\"]}"

# send an event with the same dummy source to trigger the rule
# Detail and DetailType are required but not used
aws events put-events --entries '[{"Source":"karlanka","DetailType":"X","Detail":"{}"}]'

# then change the rule back to your schedule
aws events put-rule --name "my-rule" --schedule-expression "rate(12 hours)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM