amazon-web-services - 如何将 event_api_destination 添加到 AWS 中的 cloudwatch 规则?

标签 amazon-web-services terraform amazon-cloudwatch terraform0.12+

如何将资源 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"
    }
  }
}

最佳答案

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

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
}

关于amazon-web-services - 如何将 event_api_destination 添加到 AWS 中的 cloudwatch 规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71855530/

相关文章:

amazon-web-services - Terraform 在子 AWS 账户中创建资源

node.js - 如何使用无服务器框架引用不在根文件夹中的函数?

amazon-web-services - 如何仅从静态 s3 站点调用 API 网关

azure - Terraform 启用 VM Insights

azure - Terraform 使用基于运行时传递的另一个值的变量

amazon-web-services - AWS - ELB_5XXs 和 HTTP_5XXs 之间的区别

azure - 断言失败!在 DRA 缓存中找不到虚拟机

amazon-web-services - Terraform 不会在 cloudwatch 事件目标上添加日志组名称

amazon-cloudwatch - AWS CloudWatch 何时创建新的日志流?

aws-cloudformation - 遇到不受支持的属性 ComparisonOperator