如何将event_api_destination添加到AWS中的CloudWatch规则?

发布于 2025-01-20 22:37:12 字数 1368 浏览 2 评论 0 原文

如何将资源 aws_cloudwatch_event_api_destination 和 aws_cloudwatch_event_connection 添加到 terraform 中的资源 aws_cloudwatch_event_rule ?

这段代码在下面

resource "aws_cloudwatch_event_rule" "test123_schedule_everyday" {
  name                = "${var.test123_bucket_name}-schedule-everyday-${var.env}"
  description         = "Meter reader get api data every 11:00 PM at lotus"
  schedule_expression = "cron(0 16 * * ? *)"
  is_enabled          = "${var.test123_cloudwatch_is_enable}"

  lifecycle {
    ignore_changes = [schedule_expression, description, is_enabled]
  }
}

resource "aws_cloudwatch_event_api_destination" "test123_event_api" {
  name                             = "test-dev-api"
  description                      = "test-dev-api destination"
  invocation_endpoint              = "https://test.com"
  invocation_rate_limit_per_second = "1"
  http_method                      = "GET"
  connection_arn                   = aws_cloudwatch_event_connection.test123_event_connection.arn
}

resource "aws_cloudwatch_event_connection" "test123_event_connection" {
  name               = "test-dev-connection"
  description        = "A connection description"
  authorization_type = "API_KEY"

  auth_parameters {
    api_key {
      key   = "test-key"
      value = "TUVURVJSRUFESU5HOkNCWktXWFU3NzZDS0dGTk5LNjdGWUFVNFFRNE1HV0o3"
    }
  }
}

How can i add resource aws_cloudwatch_event_api_destination and aws_cloudwatch_event_connection to resource aws_cloudwatch_event_rule in terraform?

This Code in below

resource "aws_cloudwatch_event_rule" "test123_schedule_everyday" {
  name                = "${var.test123_bucket_name}-schedule-everyday-${var.env}"
  description         = "Meter reader get api data every 11:00 PM at lotus"
  schedule_expression = "cron(0 16 * * ? *)"
  is_enabled          = "${var.test123_cloudwatch_is_enable}"

  lifecycle {
    ignore_changes = [schedule_expression, description, is_enabled]
  }
}

resource "aws_cloudwatch_event_api_destination" "test123_event_api" {
  name                             = "test-dev-api"
  description                      = "test-dev-api destination"
  invocation_endpoint              = "https://test.com"
  invocation_rate_limit_per_second = "1"
  http_method                      = "GET"
  connection_arn                   = aws_cloudwatch_event_connection.test123_event_connection.arn
}

resource "aws_cloudwatch_event_connection" "test123_event_connection" {
  name               = "test-dev-connection"
  description        = "A connection description"
  authorization_type = "API_KEY"

  auth_parameters {
    api_key {
      key   = "test-key"
      value = "TUVURVJSRUFESU5HOkNCWktXWFU3NzZDS0dGTk5LNjdGWUFVNFFRNE1HV0o3"
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2025-01-27 22:37:12

我相信您寻求的是 aws_cloudwatch_event_target。这允许您将目的地指定为给定规则的目标,如官方 API 目标文档。

resource "aws_cloudwatch_event_target" "this" {
  rule = aws_cloudwatch_event_rule.test123_schedule_everyday.name
  arn  = aws_cloudwatch_event_api_destination.test123_event_api.arn
}

I believe what you seek is an aws_cloudwatch_event_target. This allows you to specify your destination as a target for a given rule, as documented in the official API destinations documentation.

resource "aws_cloudwatch_event_target" "this" {
  rule = aws_cloudwatch_event_rule.test123_schedule_everyday.name
  arn  = aws_cloudwatch_event_api_destination.test123_event_api.arn
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文