简体   繁体   English

如何将CloudWatch规则正确附加到SNS主题?

[英]How to attach CloudWatch rule to SNS topic correctly?

I'm trying to start StepFunction from CloudWatch. 我正在尝试从CloudWatch启动StepFunction。 This works like a charm when event source is a schedule. 当事件源是日程表时,这就像一个魅力。 However, when I try to create event pattern to watch corresponding SNS topic, CloudWatch doesn't sees publications to it. 但是,当我尝试创建事件模式来观看相应的SNS主题时,CloudWatch看不到该出版物。 I've tried both default pattern: 我已经尝试了两种默认模式:

{
  "source": [
    "aws.sns"
  ]
}

And using arn: 并使用arn:

{
  "resources": [
    "// SNS topic arn here"
   ],
}

In both cases when I publish to the topic nothing happens. 在这两种情况下,当我发布主题时,都不会发生任何事情。 What am I doing wrong? 我究竟做错了什么? Update: unfortunatelly I can't understand what is "Event Pattern" rule for, it doesn't work in other condition - even when event is pushed manually from lambda. 更新:不幸的是,我不明白什么是“事件模式”规则,它在其他情况下不起作用-即使从lambda手动推送事件也是如此。 The approach to my problem I currently see is to create CloudWatch schedule rule to start every 1-3 seconds, disable it. 我目前看到的解决问题的方法是创建CloudWatch调度规则,使其每1-3秒启动一次,并将其禁用。 Then from a lambda I was going to push event to SNS enable this CloudWatch rule to fire. 然后我要从lambda将事件推送到SNS,以启用此CloudWatch规则。 When it fires and start Step Function, inside Step Function disable the rule. 当它触发并启动Step Function时,在Step Function内部禁用该规则。 It's nonsense but it should work. 这是胡说八道,但它应该可以工作。

Make sure your SNS topic has a policy set that allows events.amazonaws.com to publish to it, such as: 确保您的SNS主题具有一个允许event.amazonaws.com对其发布的策略集,例如:

  statement {
    effect  = "Allow"
    actions = ["SNS:Publish"]

    principals {
      type        = "Service"
      identifiers = ["events.amazonaws.com"]
    }

    resources = ["${aws_sns_topic.sns_topic.arn}"]
  }

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

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