具有事件模式的Terraform AWS Cloudwatch规则不起作用

时间:2020-07-30 15:28:50

标签: amazon-web-services terraform amazon-cloudwatch terraform-provider-aws

我一直面临着从terraform创建的事件模式从cloudwatch规则触发lambda的问题。

下面是我的Terraform代码:

resource "aws_cloudwatch_event_rule" "event_rule_pattern" {   
    name = "test-event-rule"   
    description = "${var.description}"   
    role_arn            = "${var.execution_role}"   
    event_pattern = <<PATTERN
     {
      "source": [
        "aws.ecs"
      ],
      "detail-type": [
        "ECS Task State Change"
      ],
      "detail": {
        "lastStatus": [
          "STOPPED"
        ],
        "taskDefinitionArn": [
          "${data.aws_ssm_parameter.task_arn.value}"
        ]
      }
    }
  PATTERN
    tags = "app"
}
    
    
resource "aws_cloudwatch_event_target" "event_target_pattern" {   
    rule = "${element(aws_cloudwatch_event_rule.event_rule_pattern.*.name, 0)}"   
    arn       = "${data.aws_ssm_parameter.special_alert_arn.value}" 
}

以上cloudwatch规则是在ECS任务完成时触发lambda。到目前为止,它能够在ECS任务完成时触发cloudwatch事件,但无法调用lambda。

Failure Image

失败后,我从aws ui控制台进行检查,只是从aws ui控制台重新保存了cloudwatch规则,它开始工作。

所以不确定,但看起来terraform无法正确配置cloudwatch规则目标,或者我做错了事。

一些地形/金刚专家可以帮忙吗?

0 个答案:

没有答案