AWS EventBridge规则在Terraform部署期间不触发步骤功能
我有一些Terraform代码来部署触发步骤功能的CloudWatch/EventBridge规则。我希望规则在每2分钟后每2分钟触发步骤函数,如下面的代码:
resource "aws_iam_role" "cw_sfn_role" {
name = "cw_sfn_role"
assume_role_policy = data.aws_iam_policy_document.sfn_trigger_policy.json
}
data "aws_iam_policy_document" "sfn_trigger_policy" {
statement {
actions = [
"sts:AssumeRole"
]
principals {
type = "Service"
identifiers = ["states.amazonaws.com",
"events.amazonaws.com"]
}
}
}
resource "aws_cloudwatch_event_rule" "step_function_trigger_event_rule" {
name = "trigger-step-function"
description = "Trigger every 2 min"
schedule_expression = "rate(2 minutes)"
is_enabled = true
}
resource "aws_cloudwatch_event_target" "step_function_target" {
arn = aws_sfn_state_machine.sfn_state_machine.arn
rule = aws_cloudwatch_event_rule.step_function_trigger_event_rule.name
role_arn = aws_iam_role.cw_sfn_role.arn
}
从AWS控制台,该规则正确连接到步骤函数,但不会触发它。同样,当我从AWS控制台手动创建规则时,触发步骤函数而没有任何问题。我怀疑问题是来自我的分配策略,或者schedue_expression
。我在这里想念什么?
I have some terraform code to deploy a cloudwatch/eventbridge rule that triggers a step function. I want the rule to trigger the step function after every 2 minutes as indicated in the code below:
resource "aws_iam_role" "cw_sfn_role" {
name = "cw_sfn_role"
assume_role_policy = data.aws_iam_policy_document.sfn_trigger_policy.json
}
data "aws_iam_policy_document" "sfn_trigger_policy" {
statement {
actions = [
"sts:AssumeRole"
]
principals {
type = "Service"
identifiers = ["states.amazonaws.com",
"events.amazonaws.com"]
}
}
}
resource "aws_cloudwatch_event_rule" "step_function_trigger_event_rule" {
name = "trigger-step-function"
description = "Trigger every 2 min"
schedule_expression = "rate(2 minutes)"
is_enabled = true
}
resource "aws_cloudwatch_event_target" "step_function_target" {
arn = aws_sfn_state_machine.sfn_state_machine.arn
rule = aws_cloudwatch_event_rule.step_function_trigger_event_rule.name
role_arn = aws_iam_role.cw_sfn_role.arn
}
From the aws console, the rule is attached correctly to the step function but it doesn't trigger it. Also, when i manually create a rule from the aws console, the step function is triggered without any issues. I suspect the problem is either from my assigned policies or schedule_expression
. What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的目标是步骤功能,因此需要允许调用其源(您的情况下的CloudWatch事件)。
这类似于Lambda的Invoke许可,以允许任何源触发它。
您为CloudWatch事件指定的角色必须包括以下权限
As your target is Step Function, it needs to allow invocation permission to its source (CloudWatch Events in your case).
This is similar to Invoke Permission for lambda to allow any source to trigger it.
The role that you specify for CloudWatch Events must include the below permissions